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