@@ -17,84 +17,85 @@ nonnull_all
17
17
static really_inline const char * scan_comment (
18
18
parser_t * parser , const char * start , const char * end )
19
19
{
20
+ assert (!parser -> file -> state .is_escaped );
21
+
20
22
while (start < end ) {
21
23
if (unlikely (* start == '\n' ))
22
24
return start ;
23
- start += 1 ;
25
+ start ++ ;
24
26
}
25
27
26
28
parser -> file -> state .in_comment = 1 ;
27
- return end ;
29
+ return start ;
28
30
}
29
31
30
32
nonnull_all
31
33
static really_inline const char * scan_quoted (
32
34
parser_t * parser , const char * start , const char * end )
33
35
{
36
+ if (unlikely (parser -> file -> state .is_escaped ))
37
+ goto escaped ;
38
+
34
39
while (start < end ) {
35
40
if (* start == '\\' ) {
36
- parser -> file -> lines .tail [0 ] += * (start + 1 ) == '\n' ;
37
- start += 2 ;
41
+ escaped :
42
+ if ((parser -> file -> state .is_escaped = (++ start == end )))
43
+ break ;
44
+ assert (start < end );
45
+ * parser -> file -> lines .tail += (* start == '\n' );
46
+ start ++ ;
38
47
} else if (* start == '\"' ) {
48
+ parser -> file -> state .in_quoted = 0 ;
39
49
* parser -> file -> delimiters .tail ++ = start ;
40
- return start + 1 ;
41
- } else if (* start == '\n' ) {
42
- parser -> file -> lines .tail [0 ]++ ;
43
- start += 1 ;
50
+ return ++ start ;
44
51
} else {
45
- start += 1 ;
52
+ * parser -> file -> lines .tail += (* start == '\n' );
53
+ start ++ ;
46
54
}
47
55
}
48
56
49
- parser -> file -> lines .tail [0 ] -= * end == '\n' ;
50
57
parser -> file -> state .in_quoted = 1 ;
51
- parser -> file -> state .is_escaped = (start > end );
52
- return end ;
58
+ return start ;
53
59
}
54
60
55
61
nonnull_all
56
62
static really_inline const char * scan_contiguous (
57
63
parser_t * parser , const char * start , const char * end )
58
64
{
65
+ if (parser -> file -> state .is_escaped )
66
+ goto escaped ;
67
+
59
68
while (start < end ) {
60
69
if (likely (classify [ (uint8_t )* start ] == CONTIGUOUS )) {
61
- if (likely (* start != '\\' )) {
62
- start += 1 ;
63
- } else {
64
- parser -> file -> lines .tail [0 ] += * (start + 1 ) == '\n' ;
65
- start += 2 ;
70
+ if (unlikely (* start == '\\' )) {
71
+ escaped :
72
+ if ((parser -> file -> state .is_escaped = (++ start == end )))
73
+ break ;
74
+ assert (start < end );
75
+ parser -> file -> lines .tail [0 ] += (* start == '\n' );
66
76
}
77
+ start ++ ;
67
78
} else {
79
+ parser -> file -> state .follows_contiguous = 0 ;
68
80
* parser -> file -> delimiters .tail ++ = start ;
69
81
return start ;
70
82
}
71
83
}
72
84
73
- parser -> file -> lines .tail [0 ] -= * end == '\n' ;
74
- parser -> file -> state .is_escaped = (start > end );
75
85
parser -> file -> state .follows_contiguous = 1 ;
76
- return end ;
86
+ return start ;
77
87
}
78
88
79
89
nonnull_all
80
90
static really_inline void scan (
81
91
parser_t * parser , const char * start , const char * end )
82
92
{
83
- if (parser -> file -> state .is_escaped ) {
84
- parser -> file -> state .is_escaped = 0 ;
85
- parser -> file -> lines .tail [0 ] += (* start ++ == '\n' );
86
- }
87
-
88
- if (parser -> file -> state .follows_contiguous ) {
89
- parser -> file -> state .follows_contiguous = 0 ;
93
+ if (parser -> file -> state .follows_contiguous )
90
94
start = scan_contiguous (parser , start , end );
91
- } if (parser -> file -> state .in_comment ) {
92
- parser -> file -> state .in_comment = 0 ;
95
+ else if (parser -> file -> state .in_comment )
93
96
start = scan_comment (parser , start , end );
94
- } else if (parser -> file -> state .in_quoted ) {
95
- parser -> file -> state .in_quoted = 0 ;
97
+ else if (parser -> file -> state .in_quoted )
96
98
start = scan_quoted (parser , start , end );
97
- }
98
99
99
100
while (start < end ) {
100
101
const int32_t code = classify [(uint8_t )* start ];
@@ -104,18 +105,17 @@ static really_inline void scan(
104
105
* parser -> file -> fields .tail ++ = start ;
105
106
start = scan_contiguous (parser , start , end );
106
107
} else if (code == LINE_FEED ) {
107
- if (parser -> file -> lines .tail [ 0 ])
108
+ if (* parser -> file -> lines .tail ) {
108
109
* parser -> file -> fields .tail ++ = line_feed ;
109
- else
110
+ parser -> file -> lines .tail ++ ;
111
+ } else {
110
112
* parser -> file -> fields .tail ++ = start ;
113
+ }
111
114
start ++ ;
112
115
} else if (code == QUOTED ) {
113
116
* parser -> file -> fields .tail ++ = start ;
114
- start = scan_quoted (parser , start + 1 , end );
115
- } else if (code == LEFT_PAREN ) {
116
- * parser -> file -> fields .tail ++ = start ;
117
- start ++ ;
118
- } else if (code == RIGHT_PAREN ) {
117
+ start = scan_quoted (parser , start + 1 , end );
118
+ } else if (code == LEFT_PAREN || code == RIGHT_PAREN ) {
119
119
* parser -> file -> fields .tail ++ = start ;
120
120
start ++ ;
121
121
} else {
0 commit comments