Переглянути джерело

new function 'luaS_hashlongstr'

Roberto Ierusalimschy 9 роки тому
батько
коміт
d356183402
2 змінених файлів з 13 додано та 2 видалено
  1. 11 1
      lstring.c
  2. 2 1
      lstring.h

+ 11 - 1
lstring.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstring.c,v 2.53 2015/09/22 14:18:24 roberto Exp roberto $
+** $Id: lstring.c,v 2.54 2015/10/08 15:53:31 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -56,6 +56,16 @@ unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
 }
 }
 
 
 
 
+unsigned int luaS_hashlongstr (TString *ts) {
+  lua_assert(ts->tt == LUA_TLNGSTR);
+  if (ts->extra == 0) {  /* no hash? */
+    ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);
+    ts->extra = 1;  /* now it has its hash */
+  }
+  return ts->hash;
+}
+
+
 /*
 /*
 ** resizes the string table
 ** resizes the string table
 */
 */

+ 2 - 1
lstring.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstring.h,v 1.59 2015/03/25 13:42:19 roberto Exp roberto $
+** $Id: lstring.h,v 1.60 2015/09/08 15:41:05 roberto Exp roberto $
 ** String table (keep all strings handled by Lua)
 ** String table (keep all strings handled by Lua)
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -34,6 +34,7 @@
 
 
 
 
 LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
 LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
+LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);
 LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
 LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
 LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
 LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
 LUAI_FUNC void luaS_clearcache (global_State *g);
 LUAI_FUNC void luaS_clearcache (global_State *g);