eliminated a function call on procfile parser
Costa Tsaousis (ktsaou) committed
Feb 18, 2018 at 01:56 UTC
4b9f86cd186efb6c8dbf342570091337acb5553b
1 file changed
+28
-19
src/procfile.c
+28
-19
@@ -39,7 +39,8 @@ char *procfile_filename(procfile *ff) {
39
// ----------------------------------------------------------------------------
40
// An array of words
41
42
-static inline void pfwords_add(procfile *ff, char *str) {
42
+NOINLINE
43
+static void pfwords_add(procfile *ff, char *str) {
44
// debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'", fw->len, str);
45
46
pfwords *fw = ff->words;
@@ -139,14 +140,6 @@ void procfile_close(procfile *ff) {
140
freez(ff);
141
}
142
142
-NOINLINE NEVERNULL
143
-static char *procfile_parser_add_word(procfile *ff, char *begin, char *end, size_t *line_words) {
144
- *end = '\0';
145
- pfwords_add(ff, begin);
146
- (*line_words)++;
147
- return end + 1;
148
-}
149
-
143
NOINLINE
144
static void procfile_parser(procfile *ff) {
145
// debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename);
@@ -171,25 +164,32 @@ static void procfile_parser(procfile *ff) {
164
s++;
165
}
166
else if(likely(ct == PF_CHAR_IS_SEPARATOR)) {
174
- if(likely(!quote && !opened)) {
175
- if (likely(s != t)) {
176
- // ending separator
177
- s = t = procfile_parser_add_word(ff, t, s, line_words);
167
+ if(!quote && !opened) {
168
+ if (s != t) {
169
+ // separator, but we have word before it
170
+ *s = '\0';
171
+ pfwords_add(ff, t);
172
+ (*line_words)++;
173
+ t = ++s;
174
}
175
else {
180
- // starting separator
176
+ // separator at the beginning
177
// skip it
178
t = ++s;
179
}
180
}
181
else {
186
- // we are inside a quote
182
+ // we are inside a quote or parenthesized string
183
s++;
184
}
185
}
186
else if(likely(ct == PF_CHAR_IS_NEWLINE)) {
187
// end of line
192
- s = t = procfile_parser_add_word(ff, t, s, line_words);
188
+
189
+ *s = '\0';
190
+ pfwords_add(ff, t);
191
+ (*line_words)++;
192
+ t = ++s;
193
194
// debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words);
195
@@ -205,7 +205,10 @@ static void procfile_parser(procfile *ff) {
205
// quote closed
206
quote = 0;
207
208
- s = t = procfile_parser_add_word(ff, t, s, line_words);
208
+ *s = '\0';
209
+ pfwords_add(ff, t);
210
+ (*line_words)++;
211
+ t = ++s;
212
}
213
else
214
s++;
@@ -227,7 +230,10 @@ static void procfile_parser(procfile *ff) {
230
opened--;
231
232
if(!opened) {
230
- s = t = procfile_parser_add_word(ff, t, s, line_words);
233
+ *s = '\0';
234
+ pfwords_add(ff, t);
235
+ (*line_words)++;
236
+ t = ++s;
237
}
238
else
239
s++;
@@ -246,7 +252,10 @@ static void procfile_parser(procfile *ff) {
252
s = &ff->data[ff->size - 1];
253
}
254
249
- procfile_parser_add_word(ff, t, s, line_words);
255
+ *s = '\0';
256
+ pfwords_add(ff, t);
257
+ (*line_words)++;
258
+ // t = ++s;
259
}
260
}
261