summaryrefslogtreecommitdiff
path: root/Build/source/libs/luajit/LuaJIT-2.0.3-PATCHES/patch-05-LuaJITTeX
blob: a33bf70ea4e394b2c43413df9ad7f506e6e77e0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
diff -ur -x lbitlib.c LuaJIT-2.0.3.orig/src/lj_def.h LuaJIT-2.0.3/src/lj_def.h
--- LuaJIT-2.0.3.orig/src/lj_def.h	2014-03-12 13:10:00.000000000 +0100
+++ LuaJIT-2.0.3/src/lj_def.h	2014-03-14 09:30:30.000000000 +0100
@@ -62,7 +62,7 @@
 #define LJ_MAX_BCINS	(1<<26)		/* Max. # of bytecode instructions. */
 #define LJ_MAX_SLOTS	250		/* Max. # of slots in a Lua func. */
 #define LJ_MAX_LOCVAR	200		/* Max. # of local variables. */
-#define LJ_MAX_UPVAL	60		/* Max. # of upvalues. */
+#define LJ_MAX_UPVAL	249		/* Max. # of upvalues. */
 
 #define LJ_MAX_IDXCHAIN	100		/* __index/__newindex chain limit. */
 #define LJ_STACK_EXTRA	5		/* Extra stack space (metamethods). */
diff -ur -x lbitlib.c LuaJIT-2.0.3.orig/src/lj_str.c LuaJIT-2.0.3/src/lj_str.c
--- LuaJIT-2.0.3.orig/src/lj_str.c	2014-03-12 13:10:00.000000000 +0100
+++ LuaJIT-2.0.3/src/lj_str.c	2014-06-02 14:10:04.000000000 +0200
@@ -90,6 +90,16 @@
   g->strhash = newhash;
 }
 
+/*
+** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to
+** compute its hash
+*/
+#if !defined(LUAI_HASHLIMIT)
+#define LUAI_HASHLIMIT		5
+#endif
+
+#define cast(t, exp)	((t)(exp))
+int luajittex_choose_hash_function = 0 ; 
 /* Intern a string and return string object. */
 GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
 {
@@ -98,27 +108,44 @@
   GCobj *o;
   MSize len = (MSize)lenx;
   MSize a, b, h = len;
+  size_t step ;
+  size_t l1 ;
   if (lenx >= LJ_MAX_STR)
     lj_err_msg(L, LJ_ERR_STROV);
   g = G(L);
+
+  if (len==0)
+    return &g->strempty; 
+  if (luajittex_choose_hash_function==0) { 
+    /* Lua 5.1.5 hash function */
+    /* for 5.2 max methods we also need to patch the vm eq */ 
+    step = (len>>LUAI_HASHLIMIT)+1;  /* if string is too long, don't hash all its chars */
+    for (l1=len; l1>=step; l1-=step)  /* compute hash */
+      h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); 
+   } else { 
+  /* LuaJIT 2.0.2 hash function */
   /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */
-  if (len >= 4) {  /* Caveat: unaligned access! */
-    a = lj_getu32(str);
-    h ^= lj_getu32(str+len-4);
-    b = lj_getu32(str+(len>>1)-2);
-    h ^= b; h -= lj_rol(b, 14);
-    b += lj_getu32(str+(len>>2)-1);
-  } else if (len > 0) {
-    a = *(const uint8_t *)str;
-    h ^= *(const uint8_t *)(str+len-1);
-    b = *(const uint8_t *)(str+(len>>1));
-    h ^= b; h -= lj_rol(b, 14);
-  } else {
-    return &g->strempty;
-  }
-  a ^= h; a -= lj_rol(h, 11);
-  b ^= a; b -= lj_rol(a, 25);
-  h ^= b; h -= lj_rol(b, 16);
+    if (len >= 4) {  /* Caveat: unaligned access! */
+      a = lj_getu32(str);
+      h ^= lj_getu32(str+len-4);
+      b = lj_getu32(str+(len>>1)-2);
+      h ^= b; h -= lj_rol(b, 14);
+      b += lj_getu32(str+(len>>2)-1);
+    } else if (len > 0) {
+      a = *(const uint8_t *)str;
+      h ^= *(const uint8_t *)(str+len-1);
+      b = *(const uint8_t *)(str+(len>>1));
+      h ^= b; h -= lj_rol(b, 14);
+    } else {
+       /* Already done, kept for reference */ 
+       return &g->strempty;
+    }
+    a ^= h; a -= lj_rol(h, 11);
+    b ^= a; b -= lj_rol(a, 25);
+    h ^= b; h -= lj_rol(b, 16);
+  } 
+
+
   /* Check if the string has already been interned. */
   o = gcref(g->strhash[h & g->strmask]);
   if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
diff -ur -x lbitlib.c LuaJIT-2.0.3.orig/src/lua.h LuaJIT-2.0.3/src/lua.h
--- LuaJIT-2.0.3.orig/src/lua.h	2014-03-14 09:15:50.000000000 +0100
+++ LuaJIT-2.0.3/src/lua.h	2014-03-14 10:08:51.000000000 +0100
@@ -103,6 +103,9 @@
 typedef LUA_INTEGER lua_Integer;
 
 
+/* communication with LuaJiTTeX */
+LUA_API int luajittex_choose_hash_function; 
+
 
 /*
 ** state manipulation