Skip to content

Commit 0089509

Browse files
committed
optimize: lj_str_new: tests the full hash value before doing the full string comparison on hash collisions. thanks Shuxin Yang for the patch.
1 parent bf7381b commit 0089509

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lj_str.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
163163
if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
164164
while (o != NULL) {
165165
GCstr *sx = gco2str(o);
166-
if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) {
166+
if (sx->len == len && sx->hash == h && str_fastcmp(str, strdata(sx), len) == 0) {
167167
/* Resurrect if dead. Can only happen with fixstring() (keywords). */
168168
if (isdead(g, o)) flipwhite(o);
169169
return sx; /* Return existing string. */
@@ -174,7 +174,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
174174
#endif
175175
while (o != NULL) {
176176
GCstr *sx = gco2str(o);
177-
if (sx->len == len && memcmp(str, strdata(sx), len) == 0) {
177+
if (sx->len == len && sx->hash == h && memcmp(str, strdata(sx), len) == 0) {
178178
/* Resurrect if dead. Can only happen with fixstring() (keywords). */
179179
if (isdead(g, o)) flipwhite(o);
180180
return sx; /* Return existing string. */

0 commit comments

Comments
 (0)