Skip to content

Commit 247be5b

Browse files
authored
Merge pull request #147 from NougatBitz/master
2 parents f2e9c7e + f3c5545 commit 247be5b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/prometheus/tokenizer.lua

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,13 @@ end
221221
function Tokenizer:parseAnnotation()
222222
if is(self, Tokenizer.ANNOTATION_START_CHARS) then
223223
self.index = self.index + 1;
224-
local source = "";
224+
local source, length = {}, 0;
225225
while(is(self, Tokenizer.ANNOTATION_CHARS)) do
226-
source = source .. get(self);
226+
source[length + 1] = get(self)
227+
length = #source
227228
end
228-
if #source > 0 then
229-
self.annotations[string.lower(source)] = true;
229+
if length > 0 then
230+
self.annotations[string.lower(table.concat(source))] = true;
230231
end
231232
return nil;
232233
end
@@ -282,17 +283,17 @@ function Tokenizer:skipWhitespaceAndComments()
282283
end
283284

284285
local function int(self, chars, seperators)
285-
local source = "";
286+
local buffer = {};
286287
while true do
287-
if(is(self, chars)) then
288-
source = source .. get(self);
289-
elseif(is(self, seperators)) then
288+
if (is(self, chars)) then
289+
buffer[#buffer + 1] = get(self)
290+
elseif (is(self, seperators)) then
290291
self.index = self.index + 1;
291292
else
292293
break
293294
end
294295
end
295-
return source;
296+
return table.concat(buffer);
296297
end
297298

298299
-- Lex the next token as a Number
@@ -367,9 +368,9 @@ end
367368
function Tokenizer:singleLineString()
368369
local startPos = self.index;
369370
local startChar = expect(self, self.StringStartLookup);
370-
local value = "";
371+
local buffer = {};
371372

372-
while(not is(self, startChar)) do
373+
while (not is(self, startChar)) do
373374
local char = get(self);
374375

375376
-- Single Line String may not contain Linebreaks except when they are escaped by \
@@ -393,7 +394,7 @@ function Tokenizer:singleLineString()
393394
char = get(self);
394395
numstr = numstr .. char;
395396
end
396-
397+
397398
if(is(self, self.NumberCharsLookup)) then
398399
char = get(self);
399400
numstr = numstr .. char;
@@ -420,12 +421,13 @@ function Tokenizer:singleLineString()
420421
end
421422
end
422423

423-
value = value .. char;
424+
--// since table.insert is slower in lua51
425+
buffer[#buffer + 1] = char
424426
end
425427

426428
expect(self, startChar);
427429

428-
return token(self, startPos, Tokenizer.TokenKind.String, value)
430+
return token(self, startPos, Tokenizer.TokenKind.String, table.concat(buffer))
429431
end
430432

431433
function Tokenizer:multiLineString()

0 commit comments

Comments
 (0)