diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-24 10:54:49 -0300 |
| commit | ef62b340e0a6b7b18931000dcbb19c4703bfe0e8 (patch) | |
| tree | d9d995116a8a686b798d1b625b06ead26f28ba58 /lstring.c | |
| parent | 5c2dd7a9e0a5b871a71ba66c4683cd88fe4f5aa4 (diff) | |
| download | lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.gz lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.tar.bz2 lua-ef62b340e0a6b7b18931000dcbb19c4703bfe0e8.zip | |
code cleaner for 16 bits.
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.35 2000/05/08 19:32:53 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.36 2000/05/10 16:33:20 roberto Exp roberto $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -34,10 +34,10 @@ void luaS_freeall (lua_State *L) { | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | static unsigned long hash_s (const char *s, long l) { | 37 | static unsigned long hash_s (const char *s, size_t l) { |
| 38 | unsigned long h = l; /* seed */ | 38 | unsigned long h = l; /* seed */ |
| 39 | long step = (l>>6)+1; /* if string is too long, don't hash all its chars */ | 39 | size_t step = (l>>6)|1; /* if string is too long, don't hash all its chars */ |
| 40 | for (; l>0; l-=step) | 40 | for (; l>=step; l-=step) |
| 41 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); | 41 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); |
| 42 | return h; | 42 | return h; |
| 43 | } | 43 | } |
| @@ -71,13 +71,13 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
| 71 | ts->nexthash = tb->hash[h]; /* chain new entry */ | 71 | ts->nexthash = tb->hash[h]; /* chain new entry */ |
| 72 | tb->hash[h] = ts; | 72 | tb->hash[h] = ts; |
| 73 | tb->nuse++; | 73 | tb->nuse++; |
| 74 | if (tb->nuse > tb->size && tb->size < MAX_INT/2) /* too crowded? */ | 74 | if (tb->nuse > (lint32)tb->size && tb->size < MAX_INT/2) /* too crowded? */ |
| 75 | luaS_resize(L, tb, tb->size*2); | 75 | luaS_resize(L, tb, tb->size*2); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | TString *luaS_newlstr (lua_State *L, const char *str, long l) { | 80 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
| 81 | unsigned long h = hash_s(str, l); | 81 | unsigned long h = hash_s(str, l); |
| 82 | int h1 = h&(L->strt.size-1); | 82 | int h1 = h&(L->strt.size-1); |
| 83 | TString *ts; | 83 | TString *ts; |
| @@ -86,7 +86,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, long l) { | |||
| 86 | return ts; | 86 | return ts; |
| 87 | } | 87 | } |
| 88 | /* not found */ | 88 | /* not found */ |
| 89 | ts = (TString *)luaM_malloc(L, sizeof(TString)+l*sizeof(char)); | 89 | ts = (TString *)luaM_malloc(L, sizeof(TString)+(lint32)l*sizeof(char)); |
| 90 | ts->marked = 0; | 90 | ts->marked = 0; |
| 91 | ts->nexthash = NULL; | 91 | ts->nexthash = NULL; |
| 92 | ts->u.s.len = l; | 92 | ts->u.s.len = l; |
