瀏覽代碼

Update string hash function to match lua 5.3.4, problem reported by masakuta at https://github.com/albertodemichelis/squirrel/issues/83

mingodad 8 年之前
父節點
當前提交
e7576d68f8
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      SquiLu/squirrel/sqstring.h

+ 2 - 2
SquiLu/squirrel/sqstring.h

@@ -5,9 +5,9 @@
 inline SQHash _hashstr (const SQChar *s, size_t l)
 {
 		SQHash h = (SQHash)l;  /* seed */
-		size_t step = (l>>5)|1;  /* if string is too long, don't hash all its chars */
+		size_t step = (l>>5)+1;  /* if string is too long, don't hash all its chars */
 		for (; l>=step; l-=step)
-			h = h ^ ((h<<5)+(h>>2)+(unsigned short)*(s++));
+			h ^= ((h<<5)+(h>>2)+(SQUChar)(s[l-1]));
 		return h;
 }