strings: compare hash as well

This commit is contained in:
Sokolov Yura aka funny_falcon 2016-05-04 07:35:43 +03:00
parent 01e4754962
commit 33af3ea00e

View File

@ -152,7 +152,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
while (o != NULL) { while (o != NULL) {
GCstr *sx = gco2str(o); GCstr *sx = gco2str(o);
if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) { if (sx->hash == h && sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) {
/* Resurrect if dead. Can only happen with fixstring() (keywords). */ /* Resurrect if dead. Can only happen with fixstring() (keywords). */
if (isdead(g, o)) flipwhite(o); if (isdead(g, o)) flipwhite(o);
return sx; /* Return existing string. */ return sx; /* Return existing string. */
@ -162,7 +162,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
} else { /* Slow path: end of string is too close to a page boundary. */ } else { /* Slow path: end of string is too close to a page boundary. */
while (o != NULL) { while (o != NULL) {
GCstr *sx = gco2str(o); GCstr *sx = gco2str(o);
if (sx->len == len && memcmp(str, strdata(sx), len) == 0) { if (sx->hash == h && sx->len == len && memcmp(str, strdata(sx), len) == 0) {
/* Resurrect if dead. Can only happen with fixstring() (keywords). */ /* Resurrect if dead. Can only happen with fixstring() (keywords). */
if (isdead(g, o)) flipwhite(o); if (isdead(g, o)) flipwhite(o);
return sx; /* Return existing string. */ return sx; /* Return existing string. */