diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-03 11:36:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-03 11:36:56 -0300 |
commit | e96385adede47a1abf160a41565ec742d3d4e413 (patch) | |
tree | 9aff6c3074d329b72b4d6a10299f30e1487e5010 /lobject.c | |
parent | 56a165bf0f061f7aff744fafd44691a2beb4b035 (diff) | |
download | lua-e96385adede47a1abf160a41565ec742d3d4e413.tar.gz lua-e96385adede47a1abf160a41565ec742d3d4e413.tar.bz2 lua-e96385adede47a1abf160a41565ec742d3d4e413.zip |
Simplification and smaller buffers for 'lua_pushfstring'
The function 'lua_pushfstring' is seldom called with large strings,
there is no need to optimize too much for that cases.
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -215,7 +215,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { | |||
215 | /* }====================================================== */ | 215 | /* }====================================================== */ |
216 | 216 | ||
217 | 217 | ||
218 | /* maximum length of a numeral */ | 218 | /* maximum length of a numeral to be converted to a number */ |
219 | #if !defined (L_MAXLENNUM) | 219 | #if !defined (L_MAXLENNUM) |
220 | #define L_MAXLENNUM 200 | 220 | #define L_MAXLENNUM 200 |
221 | #endif | 221 | #endif |
@@ -333,8 +333,15 @@ int luaO_utf8esc (char *buff, unsigned long x) { | |||
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
336 | /* maximum length of the conversion of a number to a string */ | 336 | /* |
337 | #define MAXNUMBER2STR 50 | 337 | ** Maximum length of the conversion of a number to a string. Must be |
338 | ** enough to accommodate both LUA_INTEGER_FMT and LUA_NUMBER_FMT. | ||
339 | ** (For a long long int, this is 19 digits plus a sign and a final '\0', | ||
340 | ** adding to 21. For a long double, it can go to a sign, 33 digits, | ||
341 | ** the dot, an exponent letter, an exponent sign, 5 exponent digits, | ||
342 | ** and a final '\0', adding to 43.) | ||
343 | */ | ||
344 | #define MAXNUMBER2STR 44 | ||
338 | 345 | ||
339 | 346 | ||
340 | /* | 347 | /* |
@@ -375,7 +382,7 @@ void luaO_tostring (lua_State *L, TValue *obj) { | |||
375 | */ | 382 | */ |
376 | 383 | ||
377 | /* size for buffer space used by 'luaO_pushvfstring' */ | 384 | /* size for buffer space used by 'luaO_pushvfstring' */ |
378 | #define BUFVFS 400 | 385 | #define BUFVFS 200 |
379 | 386 | ||
380 | /* buffer used by 'luaO_pushvfstring' */ | 387 | /* buffer used by 'luaO_pushvfstring' */ |
381 | typedef struct BuffFS { | 388 | typedef struct BuffFS { |
@@ -387,16 +394,16 @@ typedef struct BuffFS { | |||
387 | 394 | ||
388 | 395 | ||
389 | /* | 396 | /* |
390 | ** Push given string to the stack, as part of the buffer. If the stack | 397 | ** Push given string to the stack, as part of the buffer, and |
391 | ** is almost full, join all partial strings in the stack into one. | 398 | ** join the partial strings in the stack into one. |
392 | */ | 399 | */ |
393 | static void pushstr (BuffFS *buff, const char *str, size_t l) { | 400 | static void pushstr (BuffFS *buff, const char *str, size_t l) { |
394 | lua_State *L = buff->L; | 401 | lua_State *L = buff->L; |
395 | setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); | 402 | setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); |
396 | L->top++; /* may use one extra slot */ | 403 | L->top++; /* may use one extra slot */ |
397 | buff->pushed++; | 404 | buff->pushed++; |
398 | if (buff->pushed > 1 && L->top + 1 >= L->stack_last) { | 405 | if (buff->pushed > 1) { |
399 | luaV_concat(L, buff->pushed); /* join all partial results into one */ | 406 | luaV_concat(L, buff->pushed); /* join partial results into one */ |
400 | buff->pushed = 1; | 407 | buff->pushed = 1; |
401 | } | 408 | } |
402 | } | 409 | } |
@@ -521,8 +528,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
521 | } | 528 | } |
522 | addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */ | 529 | addstr2buff(&buff, fmt, strlen(fmt)); /* rest of 'fmt' */ |
523 | clearbuff(&buff); /* empty buffer into the stack */ | 530 | clearbuff(&buff); /* empty buffer into the stack */ |
524 | if (buff.pushed > 1) | 531 | lua_assert(buff.pushed == 1); |
525 | luaV_concat(L, buff.pushed); /* join all partial results */ | ||
526 | return svalue(s2v(L->top - 1)); | 532 | return svalue(s2v(L->top - 1)); |
527 | } | 533 | } |
528 | 534 | ||