diff --git a/src/compiler/llex.cpp b/src/compiler/llex.cpp index 0f72f3a2..d13a3a78 100644 --- a/src/compiler/llex.cpp +++ b/src/compiler/llex.cpp @@ -66,7 +66,7 @@ void luaX_init (lua_State *L) { TString *e = luaS_newliteral(L, LUA_ENV); /* create env name */ obj2gco(e)->fix(L); /* Phase 25c: never collect this name */ for (int i=0; ifix(L); /* Phase 25c: reserved words are never collected */ ts->setExtra(cast_byte(i+1)); /* reserved word */ } @@ -138,7 +138,7 @@ TString* LexState::anchorStr(TString *ts) { ** Creates a new string and anchors it in scanner's table. */ TString *LexState::newString(const char *str, size_t l) { - return anchorStr(luaS_newlstr(getLuaState(), str, l)); + return anchorStr(TString::create(getLuaState(), str, l)); } /* @@ -542,7 +542,7 @@ int LexState::lex(SemInfo *seminfo) { saveAndNext(); } while (lislalnum(getCurrentChar())); /* find or create string */ - ts = luaS_newlstr(getLuaState(), luaZ_buffer(getBuffer()), + ts = TString::create(getLuaState(), luaZ_buffer(getBuffer()), luaZ_bufflen(getBuffer())); if (isreserved(ts)) /* reserved word? */ return ts->getExtra() - 1 + FIRST_RESERVED; diff --git a/src/compiler/parseutils.cpp b/src/compiler/parseutils.cpp index 7ee8372b..9faafe26 100644 --- a/src/compiler/parseutils.cpp +++ b/src/compiler/parseutils.cpp @@ -191,7 +191,7 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, funcstate.setProto(luaF_newproto(L)); cl->setProto(funcstate.getProto()); luaC_objbarrier(L, cl, cl->getProto()); - funcstate.getProto()->setSource(luaS_new(L, name)); /* create and anchor TString */ + funcstate.getProto()->setSource(TString::create(L, name)); /* create and anchor TString */ luaC_objbarrier(L, funcstate.getProto(), funcstate.getProto()->getSource()); lexstate.setBuffer(buff); lexstate.setDyndata(dyd); diff --git a/src/core/lapi.cpp b/src/core/lapi.cpp index 82104e6f..818fc614 100644 --- a/src/core/lapi.cpp +++ b/src/core/lapi.cpp @@ -489,7 +489,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { TString *ts; lua_lock(L); - ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); + ts = (len == 0) ? TString::create(L, "") : TString::create(L, s, len); setsvalue2s(L, L->getTop().p, ts); api_incr_top(L); luaC_checkGC(L); @@ -504,7 +504,7 @@ LUA_API const char *lua_pushexternalstring (lua_State *L, lua_lock(L); api_check(L, len <= MAX_SIZE, "string too large"); api_check(L, s[len] == '\0', "string not ending with zero"); - ts = luaS_newextlstr (L, s, len, falloc, ud); + ts = TString::createExternal(L, s, len, falloc, ud); setsvalue2s(L, L->getTop().p, ts); api_incr_top(L); luaC_checkGC(L); @@ -519,7 +519,7 @@ LUA_API const char *lua_pushstring (lua_State *L, const char *s) { setnilvalue(s2v(L->getTop().p)); else { TString *ts; - ts = luaS_new(L, s); + ts = TString::create(L, s); setsvalue2s(L, L->getTop().p, ts); s = getstr(ts); /* internal copy's address */ } @@ -613,7 +613,7 @@ LUA_API int lua_pushthread (lua_State *L) { static int auxgetstr (lua_State *L, const TValue *t, const char *k) { lu_byte tag; - TString *str = luaS_new(L, k); + TString *str = TString::create(L, k); tag = luaV_fastget(t, str, s2v(L->getTop().p), luaH_getstr); if (!tagisempty(tag)) api_incr_top(L); @@ -794,7 +794,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) { */ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { int hres; - TString *str = luaS_new(L, k); + TString *str = TString::create(L, k); api_checkpop(L, 1); hres = luaV_fastset(t, str, s2v(L->getTop().p - 1), luaH_psetstr); if (hres == HOK) { @@ -1225,7 +1225,7 @@ LUA_API void lua_concat (lua_State *L, int n) { luaC_checkGC(L); } else { /* nothing to concatenate */ - setsvalue2s(L, L->getTop().p, luaS_newlstr(L, "", 0)); /* push empty string */ + setsvalue2s(L, L->getTop().p, TString::create(L, "", 0)); /* push empty string */ api_incr_top(L); } lua_unlock(L); diff --git a/src/core/ldebug.cpp b/src/core/ldebug.cpp index dc290c62..4c16dffe 100644 --- a/src/core/ldebug.cpp +++ b/src/core/ldebug.cpp @@ -895,7 +895,7 @@ l_noret lua_State::errorMsg() { } if (ttisnil(s2v(getTop().p - 1))) { /* error object is nil? */ /* change it to a proper message */ - setsvalue2s(this, getTop().p - 1, luaS_newliteral(this, "")); + setsvalue2s(this, getTop().p - 1, TString::create(this, "", 17)); } doThrow(LUA_ERRRUN); } diff --git a/src/core/ldo.cpp b/src/core/ldo.cpp index 3e5cbff9..14100d67 100644 --- a/src/core/ldo.cpp +++ b/src/core/ldo.cpp @@ -297,7 +297,7 @@ TStatus lua_State::rawRunProtected(Pfunc f, void *ud) { /* raise a stack error while running the message handler */ // Convert to lua_State method l_noret lua_State::errorError() { - TString *msg = luaS_newliteral(this, "error in error handling"); + TString *msg = TString::create(this, "error in error handling", 23); setsvalue2s(this, getTop().p, msg); getStackSubsystem().push(); /* assume EXTRA_STACK */ doThrow(LUA_ERRERR); @@ -826,7 +826,7 @@ CallInfo* lua_State::findPCall() { static int resume_error (lua_State *L, const char *msg, int narg) { api_checkpop(L, narg); L->getStackSubsystem().popN(narg); /* remove args from the stack */ - setsvalue2s(L, L->getTop().p, luaS_new(L, msg)); /* push error message */ + setsvalue2s(L, L->getTop().p, TString::create(L, msg)); /* push error message */ api_incr_top(L); lua_unlock(L); return LUA_ERRRUN; diff --git a/src/core/lstate.cpp b/src/core/lstate.cpp index ddf5b1bb..080ed367 100644 --- a/src/core/lstate.cpp +++ b/src/core/lstate.cpp @@ -214,7 +214,7 @@ static void f_luaopen (lua_State *L, void *ud) { UNUSED(ud); stack_init(L, L); /* init stack */ init_registry(L, g); - luaS_init(L); + TString::init(L); luaT_init(L); luaX_init(L); g->setGCStp(0); /* allow gc */ diff --git a/src/core/ltm.cpp b/src/core/ltm.cpp index 0c54eae8..3ba4b94c 100644 --- a/src/core/ltm.cpp +++ b/src/core/ltm.cpp @@ -48,7 +48,7 @@ void luaT_init (lua_State *L) { }; int i; for (i=0; i(TMS::TM_N); i++) { - G(L)->setTMName(i, luaS_new(L, luaT_eventname[i])); + G(L)->setTMName(i, TString::create(L, luaT_eventname[i])); obj2gco(G(L)->getTMName(i))->fix(L); /* never collect these names */ } } @@ -93,7 +93,7 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) { Table *mt; if ((ttistable(o) && (mt = hvalue(o)->getMetatable()) != nullptr) || (ttisfulluserdata(o) && (mt = uvalue(o)->getMetatable()) != nullptr)) { - const TValue *name = luaH_Hgetshortstr(mt, luaS_new(L, "__name")); + const TValue *name = luaH_Hgetshortstr(mt, TString::create(L, "__name")); if (ttisstring(name)) /* is '__name' a string? */ return getstr(tsvalue(name)); /* use it as type name */ } diff --git a/src/memory/gc/gc_collector.cpp b/src/memory/gc/gc_collector.cpp index f5bcc831..da23b5fb 100644 --- a/src/memory/gc/gc_collector.cpp +++ b/src/memory/gc/gc_collector.cpp @@ -73,7 +73,7 @@ void GCCollector::atomic(lua_State* L) { /* clear values from resurrected weak tables */ GCWeak::clearbyvalues(g, g->getWeak(), origweak); GCWeak::clearbyvalues(g, g->getAllWeak(), origall); - luaS_clearcache(g); + TString::clearCache(g); g->setCurrentWhite(cast_byte(otherwhite(g))); /* flip current white */ lua_assert(g->getGray() == nullptr); } diff --git a/src/memory/gc/gc_core.cpp b/src/memory/gc/gc_core.cpp index 56cea3d8..a91778fd 100644 --- a/src/memory/gc/gc_core.cpp +++ b/src/memory/gc/gc_core.cpp @@ -59,7 +59,7 @@ l_mem GCCore::objsize(GCObject* o) { } case LUA_VLNGSTR: { TString* ts = gco2ts(o); - res = luaS_sizelngstr(ts->getLnglen(), ts->getShrlen()); + res = TString::calculateLongStringSize(ts->getLnglen(), ts->getShrlen()); break; } case LUA_VUPVAL: { diff --git a/src/memory/gc/gc_finalizer.cpp b/src/memory/gc/gc_finalizer.cpp index 8086fba8..f03f0f51 100644 --- a/src/memory/gc/gc_finalizer.cpp +++ b/src/memory/gc/gc_finalizer.cpp @@ -46,7 +46,7 @@ void GCFinalizer::checkSizes(lua_State* L, global_State* g) { if (!g->getGCEmergency()) { if (g->getStringTable()->getNumElements() < g->getStringTable()->getSize() / 4) - luaS_resize(L, g->getStringTable()->getSize() / 2); + TString::resize(L, g->getStringTable()->getSize() / 2); } } diff --git a/src/memory/lgc.cpp b/src/memory/lgc.cpp index ed292800..3c7c72c4 100644 --- a/src/memory/lgc.cpp +++ b/src/memory/lgc.cpp @@ -443,7 +443,7 @@ void freeobj (lua_State *L, GCObject *o) { if (ts->getShrlen() == LSTRMEM) /* must free external string? */ (*ts->getFalloc())(ts->getUserData(), ts->getContentsField(), ts->getLnglen() + 1, 0); ts->~TString(); // Call destructor - luaM_freemem(L, ts, luaS_sizelngstr(ts->getLnglen(), ts->getShrlen())); + luaM_freemem(L, ts, TString::calculateLongStringSize(ts->getLnglen(), ts->getShrlen())); break; } default: lua_assert(0); diff --git a/src/objects/lobject.cpp b/src/objects/lobject.cpp index 2ee01eff..30e37b2f 100644 --- a/src/objects/lobject.cpp +++ b/src/objects/lobject.cpp @@ -462,7 +462,7 @@ unsigned luaO_tostringbuff (const TValue *obj, char *buff) { void luaO_tostring (lua_State *L, TValue *obj) { char buff[LUA_N2SBUFFSZ]; unsigned len = luaO_tostringbuff(obj, buff); - setsvalue(L, obj, luaS_newlstr(L, buff, len)); + setsvalue(L, obj, TString::create(L, buff, len)); } @@ -519,7 +519,7 @@ static void pushbuff (lua_State *L, void *ud) { } /* FALLTHROUGH */ default: { /* no errors, but it can raise one creating the new string */ - TString *ts = luaS_newlstr(L, buff->b, buff->blen); + TString *ts = TString::create(L, buff->b, buff->blen); setsvalue2s(L, L->getTop().p, ts); L->getStackSubsystem().push(); } diff --git a/src/objects/lstring.cpp b/src/objects/lstring.cpp index 430eb961..73bebf16 100644 --- a/src/objects/lstring.cpp +++ b/src/objects/lstring.cpp @@ -45,25 +45,31 @@ inline constexpr size_t tstringFallocOffset() noexcept { #endif -/* -** generic equality for strings -*/ -int luaS_eqstr (TString *a, TString *b) { - return a->equals(b); -} +// Phase 122: TString static method implementations - -// Phase 115.1: Pointer-based implementation for performance -unsigned luaS_hash (const char *str, size_t l, unsigned seed) { +unsigned TString::computeHash(const char* str, size_t l, unsigned seed) { unsigned int h = seed ^ cast_uint(l); for (; l > 0; l--) h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); return h; } +unsigned TString::computeHash(std::span str, unsigned seed) { + return computeHash(str.data(), str.size(), seed); +} -unsigned luaS_hashlongstr (TString *ts) { - return ts->hashLongStr(); +size_t TString::calculateLongStringSize(size_t len, int kind) { + switch (kind) { + case LSTRREG: /* regular long string */ + /* don't need 'falloc'/'ud', but need space for content */ + return tstringFallocOffset() + (len + 1) * sizeof(char); + case LSTRFIX: /* fixed external long string */ + /* don't need 'falloc'/'ud' */ + return tstringFallocOffset(); + default: /* external long string with deallocation */ + lua_assert(kind == LSTRMEM); + return sizeof(TString); + } } @@ -86,12 +92,7 @@ static void tablerehash (TString **vect, unsigned int osize, unsigned int nsize) } -/* -** Resize the string table. If allocation fails, keep the current size. -** (This can degrade performance, but any non-zero size should work -** correctly.) -*/ -void luaS_resize (lua_State *L, unsigned int nsize) { +void TString::resize(lua_State* L, unsigned int nsize) { stringtable *tb = G(L)->getStringTable(); unsigned int osize = tb->getSize(); TString **newvect; @@ -112,11 +113,7 @@ void luaS_resize (lua_State *L, unsigned int nsize) { } -/* -** Clear API string cache. (Entries cannot be empty, so fill them with -** a non-collectable string.) -*/ -void luaS_clearcache (global_State *g) { +void TString::clearCache(global_State* g) { unsigned int i, j; for (i = 0; i < STRCACHE_N; i++) for (j = 0; j < STRCACHE_M; j++) { @@ -126,10 +123,7 @@ void luaS_clearcache (global_State *g) { } -/* -** Initialize the string table and the string cache -*/ -void luaS_init (lua_State *L) { +void TString::init(lua_State* L) { global_State *g = G(L); unsigned int i, j; stringtable *tb = G(L)->getStringTable(); @@ -137,7 +131,7 @@ void luaS_init (lua_State *L) { tablerehash(tb->getHash(), 0, MINSTRTABSIZE); /* clear array */ tb->setSize(MINSTRTABSIZE); /* pre-create memory-error message */ - g->setMemErrMsg(luaS_newliteral(L, MEMERRMSG)); + g->setMemErrMsg(create(L, MEMERRMSG, sizeof(MEMERRMSG) - 1)); obj2gco(g->getMemErrMsg())->fix(L); /* Phase 25c: it should never be collected */ for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ for (j = 0; j < STRCACHE_M; j++) @@ -145,19 +139,7 @@ void luaS_init (lua_State *L) { } -size_t luaS_sizelngstr (size_t len, int kind) { - switch (kind) { - case LSTRREG: /* regular long string */ - /* don't need 'falloc'/'ud', but need space for content */ - return tstringFallocOffset() + (len + 1) * sizeof(char); - case LSTRFIX: /* fixed external long string */ - /* don't need 'falloc'/'ud' */ - return tstringFallocOffset(); - default: /* external long string with deallocation */ - lua_assert(kind == LSTRMEM); - return sizeof(TString); - } -} +// Phase 122: Removed luaS_sizelngstr - now TString::calculateLongStringSize() /* @@ -222,8 +204,8 @@ static TString *createstrobj (lua_State *L, size_t totalsize, lu_byte tag, } -TString *luaS_createlngstrobj (lua_State *L, size_t l) { - size_t totalsize = luaS_sizelngstr(l, LSTRREG); +TString* TString::createLongString(lua_State* L, size_t l) { + size_t totalsize = calculateLongStringSize(l, LSTRREG); TString *ts = createstrobj(L, totalsize, LUA_VLNGSTR, G(L)->getSeed()); ts->setLnglen(l); ts->setShrlen(LSTRREG); /* signals that it is a regular long string */ @@ -243,7 +225,7 @@ static void growstrtab (lua_State *L, stringtable *tb) { luaM_error(L); /* cannot even create a message... */ } if (tb->getSize() <= MAXSTRTB / 2) /* can grow string table? */ - luaS_resize(L, tb->getSize() * 2); + TString::resize(L, tb->getSize() * 2); } @@ -254,7 +236,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { TString *ts; global_State *g = G(L); stringtable *tb = g->getStringTable(); - unsigned int h = luaS_hash(str, l, g->getSeed()); + unsigned int h = TString::computeHash(str, l, g->getSeed()); TString **list = &tb->getHash()[lmod(h, tb->getSize())]; lua_assert(str != nullptr); /* otherwise 'memcmp'/'memcpy' are undefined */ for (ts = *list; ts != nullptr; ts = ts->getNext()) { @@ -283,30 +265,25 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { } -/* -** new string (with explicit length) -*/ -TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { +TString* TString::create(lua_State* L, const char* str, size_t l) { if (l <= LUAI_MAXSHORTLEN) /* short string? */ return internshrstr(L, str, l); else { TString *ts; if (l_unlikely(l * sizeof(char) >= (MAX_SIZE - sizeof(TString)))) luaM_toobig(L); - ts = luaS_createlngstrobj(L, l); + ts = createLongString(L, l); std::copy_n(str, l, getlngstr(ts)); return ts; } } +TString* TString::create(lua_State* L, std::span str) { + return create(L, str.data(), str.size()); +} -/* -** Create or reuse a zero-terminated string, first checking in the -** cache (using the string address as a key). The cache can contain -** only zero-terminated strings, so it is safe to use 'strcmp' to -** check hits. -*/ -TString *luaS_new (lua_State *L, const char *str) { + +TString* TString::create(lua_State* L, const char* str) { unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ unsigned int j; global_State *g = G(L); @@ -318,7 +295,7 @@ TString *luaS_new (lua_State *L, const char *str) { for (j = STRCACHE_M - 1; j > 0; j--) g->setStrCache(i, j, g->getStrCache(i, j - 1)); /* move out last element */ /* new element is first in the list */ - TString *newstr = luaS_newlstr(L, str, strlen(str)); + TString *newstr = create(L, str, strlen(str)); g->setStrCache(i, 0, newstr); return newstr; } @@ -365,13 +342,13 @@ struct NewExt { static void f_newext (lua_State *L, void *ud) { NewExt *ne = static_cast(ud); - size_t size = luaS_sizelngstr(0, ne->kind); + size_t size = TString::calculateLongStringSize(0, ne->kind); ne->ts = createstrobj(L, size, LUA_VLNGSTR, G(L)->getSeed()); } -TString *luaS_newextlstr (lua_State *L, - const char *s, size_t len, lua_Alloc falloc, void *ud) { +TString* TString::createExternal(lua_State* L, const char* s, size_t len, + lua_Alloc falloc, void* ud) { struct NewExt ne; if (!falloc) { ne.kind = LSTRFIX; @@ -401,7 +378,7 @@ unsigned TString::hashLongStr() { lua_assert(getType() == LUA_VLNGSTR); if (getExtra() == 0) { /* no hash? */ size_t len = getLnglen(); - setHash(luaS_hash(getlngstr(this), len, getHash())); + setHash(computeHash(getlngstr(this), len, getHash())); setExtra(1); /* now it has its hash */ } return getHash(); diff --git a/src/objects/lstring.h b/src/objects/lstring.h index 26f7bd60..8dffd73b 100644 --- a/src/objects/lstring.h +++ b/src/objects/lstring.h @@ -174,14 +174,27 @@ class TString : public GCBase { return sizeof(OffsetHelper); } - // Method declarations (implemented in lstring.cpp) + // Instance methods (implemented in lstring.cpp) unsigned hashLongStr(); bool equals(const TString* other) const; void remove(lua_State* L); // Phase 25a: from luaS_remove TString* normalize(lua_State* L); // Phase 25a: from luaS_normstr - // Static factory-like functions (still use luaS_* for now) - // static TString* create(lua_State* L, const char* str, size_t len); + // Phase 122: Static helpers and factory methods (from luaS_*) + static unsigned computeHash(const char* str, size_t l, unsigned seed); + static unsigned computeHash(std::span str, unsigned seed); + static size_t calculateLongStringSize(size_t len, int kind); + static TString* create(lua_State* L, const char* str, size_t l); + static TString* create(lua_State* L, std::span str); + static TString* create(lua_State* L, const char* str); // null-terminated + static TString* createLongString(lua_State* L, size_t l); + static TString* createExternal(lua_State* L, const char* s, size_t len, + lua_Alloc falloc, void* ud); + + // Phase 122: Global string table management + static void init(lua_State* L); + static void resize(lua_State* L, unsigned int newsize); + static void clearCache(global_State* g); // Comparison operator overloads (defined after l_strcmp declaration) friend bool operator<(const TString& l, const TString& r) noexcept; @@ -276,7 +289,7 @@ inline constexpr size_t sizestrshr(size_t l) noexcept { /* Create a new string from a string literal, computing length at compile time */ template inline TString* luaS_newliteral(lua_State *L, const char (&s)[N]) { - return luaS_newlstr(L, s, N - 1); + return TString::create(L, s, N - 1); } @@ -296,31 +309,13 @@ inline bool eqshrstr(const TString* a, const TString* b) noexcept { } -// Phase 115.1: Primary implementations use pointer+size for performance -LUAI_FUNC unsigned luaS_hash (const char *str, size_t l, unsigned seed); -LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); +// Phase 122: Non-TString functions +LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, unsigned short nuvalue); -// std::span overloads (inline wrappers for convenience) -inline unsigned luaS_hash (std::span str, unsigned seed) { - return luaS_hash(str.data(), str.size(), seed); -} -inline TString *luaS_newlstr (lua_State *L, std::span str) { - return luaS_newlstr(L, str.data(), str.size()); -} - -LUAI_FUNC unsigned luaS_hashlongstr (TString *ts); -LUAI_FUNC int luaS_eqstr (TString *a, TString *b); -LUAI_FUNC void luaS_resize (lua_State *L, unsigned int newsize); -LUAI_FUNC void luaS_clearcache (global_State *g); -LUAI_FUNC void luaS_init (lua_State *L); /* Phase 26: Removed luaS_remove - now TString::remove() method */ -LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, - unsigned short nuvalue); -LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); -LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); -LUAI_FUNC TString *luaS_newextlstr (lua_State *L, - const char *s, size_t len, lua_Alloc falloc, void *ud); -LUAI_FUNC size_t luaS_sizelngstr (size_t len, int kind); /* Phase 26: Removed luaS_normstr - now TString::normalize() method */ +/* Phase 122: Removed luaS_hash, luaS_newlstr, luaS_new, luaS_createlngstrobj, + luaS_newextlstr, luaS_sizelngstr, luaS_hashlongstr, luaS_eqstr, + luaS_init, luaS_resize, luaS_clearcache - now TString:: methods */ #endif diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index 43829f72..0133df58 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -323,7 +323,7 @@ static Node *mainpositionTV (const Table *t, const TValue *key) { } case LUA_VLNGSTR: { TString *ts = tsvalue(key); - return hashpow2(t, luaS_hashlongstr(ts)); + return hashpow2(t, ts->hashLongStr()); } case LUA_VFALSE: return hashboolean(t, 0); @@ -375,7 +375,7 @@ static bool equalkey (const TValue *k1, const Node *n2, int deadok) { if (rawtt(k1) != n2->getKeyType()) { /* not the same variants? */ if (n2->isKeyShrStr() && ttislngstring(k1)) { /* an external string can be equal to a short-string key */ - return luaS_eqstr(tsvalue(k1), n2->getKeyStrValue()); + return tsvalue(k1)->equals(n2->getKeyStrValue()); } else if (deadok && n2->isKeyDead() && iscollectable(k1)) { /* a collectable value can be equal to a dead key */ @@ -397,7 +397,7 @@ static bool equalkey (const TValue *k1, const Node *n2, int deadok) { case LUA_VLCF: return fvalue(k1) == fvalueraw(n2->getKeyValue()); case ctb(LUA_VLNGSTR): - return luaS_eqstr(tsvalue(k1), n2->getKeyStrValue()); + return tsvalue(k1)->equals(n2->getKeyStrValue()); default: return gcvalue(k1) == gcvalueraw(n2->getKeyValue()); } diff --git a/src/serialization/lundump.cpp b/src/serialization/lundump.cpp index 69568b26..8d01fba1 100644 --- a/src/serialization/lundump.cpp +++ b/src/serialization/lundump.cpp @@ -171,16 +171,16 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { else if ((size -= 2) <= LUAI_MAXSHORTLEN) { /* short string? */ char buff[LUAI_MAXSHORTLEN + 1]; /* extra space for '\0' */ loadVector(S, buff, size + 1); /* load string into buffer */ - *sl = ts = luaS_newlstr(L, buff, size); /* create string */ + *sl = ts = TString::create(L, buff, size); /* create string */ luaC_objbarrier(L, p, ts); } else if (S->fixed) { /* for a fixed buffer, use a fixed string */ const char *s = getaddr(S, size + 1, char); /* get content address */ - *sl = ts = luaS_newextlstr(L, s, size, nullptr, nullptr); + *sl = ts = TString::createExternal(L, s, size, nullptr, nullptr); luaC_objbarrier(L, p, ts); } else { /* create internal copy */ - *sl = ts = luaS_createlngstrobj(L, size); /* create string */ + *sl = ts = TString::createLongString(L, size); /* create string */ luaC_objbarrier(L, p, ts); loadVector(S, getlngstr(ts), size + 1); /* load directly in final place */ } diff --git a/src/testing/ltests.cpp b/src/testing/ltests.cpp index f42cbb29..4a87c4d2 100644 --- a/src/testing/ltests.cpp +++ b/src/testing/ltests.cpp @@ -1090,7 +1090,7 @@ static int hash_query (lua_State *L) { luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); ts = tsvalue(obj_at(L, 1)); if (ts->getType() == LUA_VLNGSTR) - luaS_hashlongstr(ts); /* make sure long string has a hash */ + ts->hashLongStr(); /* make sure long string has a hash */ lua_pushinteger(L, cast_int(ts->getHash())); } else { diff --git a/src/vm/lvm_comparison.cpp b/src/vm/lvm_comparison.cpp index 4dc7921d..7115a371 100644 --- a/src/vm/lvm_comparison.cpp +++ b/src/vm/lvm_comparison.cpp @@ -209,7 +209,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { /* compare two strings with different variants: they can be equal when one string is a short string and the other is an external string */ - return luaS_eqstr(tsvalue(t1), tsvalue(t2)); + return tsvalue(t1)->equals(tsvalue(t2)); } default: /* only numbers (integer/float) and strings (long/short) can have @@ -229,7 +229,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); case LUA_VLNGSTR: - return luaS_eqstr(tsvalue(t1), tsvalue(t2)); + return tsvalue(t1)->equals(tsvalue(t2)); case LUA_VUSERDATA: { if (uvalue(t1) == uvalue(t2)) return 1; else if (L == nullptr) return 0; diff --git a/src/vm/lvm_string.cpp b/src/vm/lvm_string.cpp index 754c72be..7e3c25e4 100644 --- a/src/vm/lvm_string.cpp +++ b/src/vm/lvm_string.cpp @@ -86,11 +86,11 @@ void luaV_concat (lua_State *L, int total) { if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */ char buff[LUAI_MAXSHORTLEN]; copy2buff(top, n, buff); /* copy strings to buffer */ - ts = luaS_newlstr(L, buff, tl); + ts = TString::create(L, buff, tl); top = L->getTop().p; /* recapture after potential GC */ } else { /* long string; copy strings directly to final result */ - ts = luaS_createlngstrobj(L, tl); + ts = TString::createLongString(L, tl); top = L->getTop().p; /* recapture after potential GC */ copy2buff(top, n, getlngstr(ts)); }