aboutsummaryrefslogtreecommitdiff
path: root/src/lj_api.c
diff options
context:
space:
mode:
authorMike Pall <mike>2021-03-25 02:15:26 +0100
committerMike Pall <mike>2021-03-25 02:15:26 +0100
commit836fb5bbd3a0d48cf3e4de70535925a85aea835f (patch)
tree616364b1e3519a59dad464afa494199a554cfca0 /src/lj_api.c
parentda20ea45c477a11aa62ba32c0089ff174be76406 (diff)
downloadluajit-836fb5bbd3a0d48cf3e4de70535925a85aea835f.tar.gz
luajit-836fb5bbd3a0d48cf3e4de70535925a85aea835f.tar.bz2
luajit-836fb5bbd3a0d48cf3e4de70535925a85aea835f.zip
Reorganize lightuserdata interning code.
Diffstat (limited to 'src/lj_api.c')
-rw-r--r--src/lj_api.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/src/lj_api.c b/src/lj_api.c
index 8b00436d..18a7ecbc 100644
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -707,36 +707,10 @@ LUA_API void lua_pushboolean(lua_State *L, int b)
707 incr_top(L); 707 incr_top(L);
708} 708}
709 709
710#if LJ_64
711static void *lightud_intern(lua_State *L, void *p)
712{
713 global_State *g = G(L);
714 uint64_t u = (uint64_t)p;
715 uint32_t up = lightudup(u);
716 uint32_t *segmap = mref(g->gc.lightudseg, uint32_t);
717 MSize segnum = g->gc.lightudnum;
718 if (segmap) {
719 MSize seg;
720 for (seg = 0; seg <= segnum; seg++)
721 if (segmap[seg] == up) /* Fast path. */
722 return (void *)(((uint64_t)seg << LJ_LIGHTUD_BITS_LO) | lightudlo(u));
723 segnum++;
724 }
725 if (!((segnum-1) & segnum) && segnum != 1) {
726 if (segnum >= (1 << LJ_LIGHTUD_BITS_SEG)) lj_err_msg(L, LJ_ERR_BADLU);
727 lj_mem_reallocvec(L, segmap, segnum, segnum ? 2*segnum : 2u, uint32_t);
728 setmref(g->gc.lightudseg, segmap);
729 }
730 g->gc.lightudnum = segnum;
731 segmap[segnum] = up;
732 return (void *)(((uint64_t)segnum << LJ_LIGHTUD_BITS_LO) | lightudlo(u));
733}
734#endif
735
736LUA_API void lua_pushlightuserdata(lua_State *L, void *p) 710LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
737{ 711{
738#if LJ_64 712#if LJ_64
739 p = lightud_intern(L, p); 713 p = lj_lightud_intern(L, p);
740#endif 714#endif
741 setrawlightudV(L->top, p); 715 setrawlightudV(L->top, p);
742 incr_top(L); 716 incr_top(L);
@@ -1179,7 +1153,7 @@ static TValue *cpcall(lua_State *L, lua_CFunction func, void *ud)
1179 setfuncV(L, top++, fn); 1153 setfuncV(L, top++, fn);
1180 if (LJ_FR2) setnilV(top++); 1154 if (LJ_FR2) setnilV(top++);
1181#if LJ_64 1155#if LJ_64
1182 ud = lightud_intern(L, ud); 1156 ud = lj_lightud_intern(L, ud);
1183#endif 1157#endif
1184 setrawlightudV(top++, ud); 1158 setrawlightudV(top++, ud);
1185 cframe_nres(L->cframe) = 1+0; /* Zero results. */ 1159 cframe_nres(L->cframe) = 1+0; /* Zero results. */