commit 9329eeac3b7035c223d7a8b63dbde1f6db371bf5
parent 682efe2678589eebc7c982e0ed66ad4990711e5a
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 27 Nov 2024 18:37:02 -0300
Avoid an extra call to 'concretesize' in 'resizearray'
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/ltable.c b/ltable.c
@@ -632,14 +632,14 @@ static Value *resizearray (lua_State *L , Table *t,
if (np == NULL) /* allocation error? */
return NULL;
if (oldasize > 0) {
+ size_t oldasizeb = concretesize(oldasize);
/* move common elements to new position */
Value *op = t->array - oldasize; /* real original array */
unsigned tomove = (oldasize < newasize) ? oldasize : newasize;
- lua_assert(tomove > 0);
- memcpy(np + newasize - tomove,
- op + oldasize - tomove,
- concretesize(tomove));
- luaM_freemem(L, op, concretesize(oldasize));
+ size_t tomoveb = (oldasize < newasize) ? oldasizeb : newasizeb;
+ lua_assert(tomoveb > 0);
+ memcpy(np + newasize - tomove, op + oldasize - tomove, tomoveb);
+ luaM_freemem(L, op, oldasizeb);
}
return np + newasize; /* shift pointer to the end of value segment */
}