diff --git a/src/lib_base.c b/src/lib_base.c index 999e4c8f..3d5eb222 100644 --- a/src/lib_base.c +++ b/src/lib_base.c @@ -222,16 +222,10 @@ LJLIB_CF(rawlen) LJLIB_REC(.) LJLIB_CF(unpack) { -#if LJ_DS_UNPACK_PATCH -#define TAB_LEN lj_tab_arraylen -#else -#define TAB_LEN lj_tab_len -#endif - GCtab *t = lj_lib_checktab(L, 1); int32_t n, i = lj_lib_optint(L, 2, 1); int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ? - lj_lib_checkint(L, 3) : (int32_t)TAB_LEN(t); + lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t); uint32_t nu; if (i > e) return 0; nu = (uint32_t)e - (uint32_t)i; diff --git a/src/lj_arch.h b/src/lj_arch.h index c4398121..5b709f1d 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -751,8 +751,8 @@ extern void *LJ_WIN_LOADLIBA(const char *path); #define LJ_DS_BIG_UPVAL_PATCH LJ_DS #endif -#ifndef LJ_DS_UNPACK_PATCH -#define LJ_DS_UNPACK_PATCH LJ_DS +#ifndef LJ_DS_PARSER_TABLE_PATCH +#define LJ_DS_PARSER_TABLE_PATCH LJ_DS #endif #ifndef LJ_NO_SYSTEM diff --git a/src/lj_parse.c b/src/lj_parse.c index 8e0e9113..675fd228 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c @@ -1807,8 +1807,14 @@ static void expr_table(LexState *ls, ExpDesc *e) else if (narr > 0x7ff) narr = 0x7ff; setbc_d(ip, narr|(hsize2hbits(nhash)<<11)); } else { +#if LJ_DS_PARSER_TABLE_PATCH + if ((needarr && t->asize != narr) || hsize2hmask(nhash) != t->hmask) { + lj_tab_resize(fs->L, t, narr, hsize2hbits(nhash)); + } +#else if (needarr && t->asize < narr) lj_tab_reasize(fs->L, t, narr-1); +#endif if (fixt) { /* Fix value for dummy keys in template table. */ Node *node = noderef(t->node); uint32_t i, hmask = t->hmask; diff --git a/src/lj_tab.c b/src/lj_tab.c index 1019a745..568c0288 100644 --- a/src/lj_tab.c +++ b/src/lj_tab.c @@ -691,14 +691,3 @@ MSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint) } #endif -#if LJ_DS_UNPACK_PATCH -MSize LJ_FASTCALL lj_tab_arraylen(GCtab *t) -{ - MSize j = (MSize)t->asize; - while (j > 1 && tvisnil(arrayslot(t, j - 1))) { - j--; - } - if (j) --j; - return j; -} -#endif diff --git a/src/lj_tab.h b/src/lj_tab.h index 95624ac4..611959f5 100644 --- a/src/lj_tab.h +++ b/src/lj_tab.h @@ -43,7 +43,7 @@ static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash) #define hashlohi(t, lo, hi) hashmask((t), hashrot((lo), (hi))) #define hashnum(t, o) hashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1)) -#if LJ_GC64 +#if LJ_GC64 #define hashgcref(t, r) \ hashlohi((t), (uint32_t)gcrefu(r), (uint32_t)(gcrefu(r) >> 32)) #else @@ -51,6 +51,7 @@ static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash) #endif #define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0) +#define hsize2hmask(s) ((s) ? (1u <