… | |
… | |
175 | /* this is primitive, yet effective */ |
175 | /* this is primitive, yet effective */ |
176 | /* the returned value must never be zero (or bad things will happen) */ |
176 | /* the returned value must never be zero (or bad things will happen) */ |
177 | static U32 |
177 | static U32 |
178 | lru_hash (SV *dbh, SV *sql) |
178 | lru_hash (SV *dbh, SV *sql) |
179 | { |
179 | { |
|
|
180 | /* use a variant of fnv1a */ |
180 | STRLEN i, l; |
181 | STRLEN i, l; |
181 | char *b = SvPV (sql, l); |
182 | char *b = SvPV (sql, l); |
182 | U32 hash = 2166136261U; |
183 | U32 hash = 2166136261U; |
183 | |
184 | |
184 | hash = (hash ^ (U32)dbh) * 16777619U; |
185 | hash = (hash ^ (U32)dbh) * 16777619U; |
185 | hash = (hash ^ l) * 16777619U; |
186 | hash = (hash ^ l) * 16777619U; |
186 | |
187 | |
187 | /* start hashing at char 8, as this skips the "select " prefix */ |
188 | /* start hashing at char 7, as this skips the "select " prefix */ |
|
|
189 | /* also skip more and more octets */ |
188 | for (i = 7; i < l; i += i >> 2) |
190 | for (i = 7; i < l; i += i >> 2) |
189 | hash = (hash ^ b [i]) * 16777619U; |
191 | hash = (hash ^ b [i]) * 16777619U; |
190 | |
192 | |
191 | return hash; |
193 | return hash; |
192 | } |
194 | } |
193 | |
195 | |
194 | /* fetch and "use" */ |
196 | /* fetch and "use" */ |