Skip to content

Commit c64a0e8

Browse files
authored
refactor: remove unnecessary stack (#17)
1 parent 57f4687 commit c64a0e8

4 files changed

Lines changed: 48 additions & 56 deletions

File tree

errors.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import (
99

1010
// Sentinel errors returned by [Reader]. These are compatible with [encoding/csv].
1111
var (
12-
ErrBareQuote = errors.New("bare \" in non-quoted-field")
13-
ErrQuote = errors.New("extraneous or missing \" in quoted-field")
14-
ErrFieldCount = errors.New("wrong number of fields")
15-
ErrTrailingComma = errors.New("extra delimiter at end of line") // Deprecated
12+
ErrBareQuote = errors.New("bare \" in non-quoted-field")
13+
ErrQuote = errors.New("extraneous or missing \" in quoted-field")
14+
ErrFieldCount = errors.New("wrong number of fields")
1615
)
1716

1817
// ParseError represents a parsing error with location information

field_parser_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestParseBuffer(t *testing.T) {
8989

9090
sr := &scanResult{
9191
quoteMasks: []uint64{0},
92-
separatorMasks: []uint64{0b010101010}, // bits 1,3,5,7 (commas)
92+
separatorMasks: []uint64{0b010101010}, // bits 1,3,5,7 (commas)
9393
newlineMasks: []uint64{0b1000000000}, // bit 9 (newline)
9494
chunkCount: 1,
9595
lastChunkBits: 10,
@@ -116,7 +116,7 @@ func TestParseBuffer(t *testing.T) {
116116
sr := &scanResult{
117117
quoteMasks: []uint64{0, 0},
118118
separatorMasks: []uint64{0b1000010000000, 0b10000000}, // commas in each chunk
119-
newlineMasks: []uint64{1 << 20, 1 << 13}, // newlines
119+
newlineMasks: []uint64{1 << 20, 1 << 13}, // newlines
120120
chunkCount: 2,
121121
lastChunkBits: 64,
122122
}
@@ -378,7 +378,7 @@ func TestRowsInitialization(t *testing.T) {
378378
// Positions: 0=a 1=, 2=b 3=, 4=c 5=\n 6=d 7=, 8=e 9=\n 10=f 11=, 12=g 13=, 14=h 15=, 16=i 17=\n
379379
sr := &scanResult{
380380
quoteMasks: []uint64{0},
381-
separatorMasks: []uint64{0b1010100010001010}, // commas at 1,3,7,11,13,15
381+
separatorMasks: []uint64{0b1010100010001010}, // commas at 1,3,7,11,13,15
382382
newlineMasks: []uint64{0b100000001000100000}, // newlines at 5, 9, 17
383383
chunkCount: 1,
384384
lastChunkBits: 18,
@@ -603,7 +603,7 @@ func TestQuoteHandling(t *testing.T) {
603603
// would not include it in separatorMask
604604
sr := &scanResult{
605605
quoteMasks: []uint64{(1 << 0) | (1 << 4)}, // quotes at 0,4
606-
separatorMasks: []uint64{1 << 5}, // only comma at 5
606+
separatorMasks: []uint64{1 << 5}, // only comma at 5
607607
newlineMasks: []uint64{1 << 7},
608608
chunkCount: 1,
609609
lastChunkBits: 8,
@@ -844,7 +844,7 @@ func TestEdgeCases(t *testing.T) {
844844

845845
sr := &scanResult{
846846
quoteMasks: []uint64{0},
847-
separatorMasks: []uint64{0b010101010}, // commas at 1,3,5,7
847+
separatorMasks: []uint64{0b010101010}, // commas at 1,3,5,7
848848
newlineMasks: []uint64{0b1000000000}, // newline at 9
849849
chunkCount: 1,
850850
lastChunkBits: 10,
@@ -868,7 +868,7 @@ func TestEdgeCases(t *testing.T) {
868868
sr := &scanResult{
869869
quoteMasks: []uint64{0},
870870
separatorMasks: []uint64{0b00110}, // commas at 1,3
871-
newlineMasks: []uint64{0}, // no newlines
871+
newlineMasks: []uint64{0}, // no newlines
872872
chunkCount: 1,
873873
lastChunkBits: 5,
874874
}

reader.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ type Reader struct {
5050
// By default, each call to Read returns newly allocated memory owned by the caller.
5151
ReuseRecord bool
5252

53-
// Deprecated: TrailingComma is no longer used.
54-
TrailingComma bool
55-
5653
r io.Reader
5754

5855
// Internal state
59-
numLine int
6056
offset int64
6157
rawBuffer []byte
6258
fieldPositions []position
@@ -116,9 +112,6 @@ func (r *Reader) Read() (record []string, err error) {
116112
rowInfo := r.parseResult.rows[r.currentRecordIndex]
117113
r.currentRecordIndex++
118114

119-
// Update line number for error reporting
120-
r.numLine = rowInfo.lineNum
121-
122115
// Check for comment line (line starting with Comment character)
123116
if r.Comment != 0 && r.isCommentLine(rowInfo) {
124117
// Skip this line and continue to next

simd_scanner_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ func makeAligned64(data []byte) []byte {
8383

8484
func TestGenerateMasks(t *testing.T) {
8585
tests := []struct {
86-
name string
87-
input []byte
88-
separator byte
89-
wantQuotePos []int // expected bit positions for quotes
90-
wantSepPos []int // expected bit positions for separators
91-
wantCRPos []int // expected bit positions for CR
92-
wantNLPos []int // expected bit positions for LF
86+
name string
87+
input []byte
88+
separator byte
89+
wantQuotePos []int // expected bit positions for quotes
90+
wantSepPos []int // expected bit positions for separators
91+
wantCRPos []int // expected bit positions for CR
92+
wantNLPos []int // expected bit positions for LF
9393
}{
9494
{
9595
name: "simple_csv_line",
@@ -279,14 +279,14 @@ func TestGenerateMasks(t *testing.T) {
279279

280280
func TestGenerateMasksPadded(t *testing.T) {
281281
tests := []struct {
282-
name string
283-
input []byte
284-
separator byte
285-
wantQuotePos []int
286-
wantSepPos []int
287-
wantCRPos []int
288-
wantNLPos []int
289-
wantValidBits int
282+
name string
283+
input []byte
284+
separator byte
285+
wantQuotePos []int
286+
wantSepPos []int
287+
wantCRPos []int
288+
wantNLPos []int
289+
wantValidBits int
290290
}{
291291
{
292292
name: "single_byte",
@@ -485,8 +485,8 @@ func TestCRLFNormalization(t *testing.T) {
485485
tests := []struct {
486486
name string
487487
input []byte
488-
wantNewlinePos []int // positions in final newline mask (after normalization)
489-
wantCRLFNormalized bool // true if CRLF was normalized
488+
wantNewlinePos []int // positions in final newline mask (after normalization)
489+
wantCRLFNormalized bool // true if CRLF was normalized
490490
description string
491491
}{
492492
{
@@ -586,19 +586,19 @@ func TestCRLFNormalization(t *testing.T) {
586586
// CR at byte 63 of chunk N, LF at byte 0 of chunk N+1
587587
func TestCRLFBoundary(t *testing.T) {
588588
tests := []struct {
589-
name string
590-
chunk1 []byte // first 64-byte chunk (CR at end)
591-
chunk2 []byte // second 64-byte chunk (LF at start)
592-
wantChunk1NL []int // newline positions in chunk 1
593-
wantChunk2NL []int // newline positions in chunk 2
594-
description string
589+
name string
590+
chunk1 []byte // first 64-byte chunk (CR at end)
591+
chunk2 []byte // second 64-byte chunk (LF at start)
592+
wantChunk1NL []int // newline positions in chunk 1
593+
wantChunk2NL []int // newline positions in chunk 2
594+
description string
595595
}{
596596
{
597597
name: "boundary_crlf",
598598
chunk1: append(make([]byte, 63), '\r'),
599599
chunk2: append([]byte{'\n'}, make([]byte, 63)...),
600-
wantChunk1NL: nil, // CR at 63 is part of CRLF, not counted here
601-
wantChunk2NL: []int{0}, // LF at 0 is the actual newline
600+
wantChunk1NL: nil, // CR at 63 is part of CRLF, not counted here
601+
wantChunk2NL: []int{0}, // LF at 0 is the actual newline
602602
description: "CRLF split across chunk boundary",
603603
},
604604
{
@@ -711,8 +711,8 @@ func TestChunkBoundaryQuotes(t *testing.T) {
711711
name: "boundary_escaped_quote_inside_field",
712712
chunk1: append(append([]byte(`"content`), make([]byte, 55)...), '"'),
713713
chunk2: append([]byte{'"', 'm', 'o', 'r', 'e', '"'}, make([]byte, 58)...),
714-
chunk1Quoted: false, // starts outside
715-
wantSkipNextQuote: true, // "" at boundary
714+
chunk1Quoted: false, // starts outside
715+
wantSkipNextQuote: true, // "" at boundary
716716
wantChunk2QuoteSkip: true,
717717
description: `"content..." with "" escape at boundary`,
718718
},
@@ -841,8 +841,8 @@ func TestScanBuffer(t *testing.T) {
841841
input []byte
842842
separator byte
843843
wantChunkCount int
844-
wantPostProcChunks []int // chunks that need post-processing (have escaped quotes)
845-
wantFinalQuoted bool // should we end in quoted state?
844+
wantPostProcChunks []int // chunks that need post-processing (have escaped quotes)
845+
wantFinalQuoted bool // should we end in quoted state?
846846
description string
847847
}{
848848
{
@@ -959,14 +959,14 @@ func TestScanBuffer(t *testing.T) {
959959
// TestScanBuffer_MaskContent verifies the actual mask content
960960
func TestScanBuffer_MaskContent(t *testing.T) {
961961
tests := []struct {
962-
name string
963-
input []byte
964-
separator byte
965-
chunkIdx int
966-
wantSepPos []int
967-
wantNLPos []int
968-
wantQuotePos []int
969-
description string
962+
name string
963+
input []byte
964+
separator byte
965+
chunkIdx int
966+
wantSepPos []int
967+
wantNLPos []int
968+
wantQuotePos []int
969+
description string
970970
}{
971971
{
972972
name: "verify_separator_positions",
@@ -1034,8 +1034,8 @@ func TestScanBuffer_MultiChunk(t *testing.T) {
10341034
// Chunk 1: bytes 64-127
10351035
// Chunk 2: bytes 128+
10361036
chunk0 := strings.Repeat("a,", 20) + "field\n" + strings.Repeat("b,", 10) // ~66 bytes
1037-
chunk1 := strings.Repeat("c,", 25) + "data\n" // ~55 bytes
1038-
chunk2 := "last\n" // 5 bytes
1037+
chunk1 := strings.Repeat("c,", 25) + "data\n" // ~55 bytes
1038+
chunk2 := "last\n" // 5 bytes
10391039

10401040
input := []byte(chunk0 + chunk1 + chunk2)
10411041

0 commit comments

Comments
 (0)