diff options
author | Sébastien SAUVAGE <sebsauvage@sebsauvage.net> | 2013-11-29 13:01:08 -0800 |
---|---|---|
committer | Sébastien SAUVAGE <sebsauvage@sebsauvage.net> | 2013-11-29 13:01:08 -0800 |
commit | ab0638edb0b23e404e05c88c1029b98ad4dd9613 (patch) | |
tree | 039466e60ade2a303cb789e80772e355d2d40788 | |
parent | 53da201749f8f362323ef278bf338f1d9f7a925a (diff) | |
parent | c002ca9c6ba1d40cda342ca85fb48acda39d7e52 (diff) | |
download | Shaarli-ab0638edb0b23e404e05c88c1029b98ad4dd9613.tar.gz Shaarli-ab0638edb0b23e404e05c88c1029b98ad4dd9613.tar.zst Shaarli-ab0638edb0b23e404e05c88c1029b98ad4dd9613.zip |
Merge pull request #145 from Alkarex/patch-1
smallHash: simplified and improved performance
-rw-r--r-- | index.php | 7 |
1 files changed, 2 insertions, 5 deletions
@@ -221,7 +221,7 @@ function nl2br_escaped($html) | |||
221 | return str_replace('>','>',str_replace('<','<',nl2br($html))); | 221 | return str_replace('>','>',str_replace('<','<',nl2br($html))); |
222 | } | 222 | } |
223 | 223 | ||
224 | /* Returns the small hash of a string | 224 | /* Returns the small hash of a string, using RFC 4648 base64url format |
225 | eg. smallHash('20111006_131924') --> yZH23w | 225 | eg. smallHash('20111006_131924') --> yZH23w |
226 | Small hashes: | 226 | Small hashes: |
227 | - are unique (well, as unique as crc32, at last) | 227 | - are unique (well, as unique as crc32, at last) |
@@ -233,10 +233,7 @@ function nl2br_escaped($html) | |||
233 | function smallHash($text) | 233 | function smallHash($text) |
234 | { | 234 | { |
235 | $t = rtrim(base64_encode(hash('crc32',$text,true)),'='); | 235 | $t = rtrim(base64_encode(hash('crc32',$text,true)),'='); |
236 | $t = str_replace('+','-',$t); // Get rid of characters which need encoding in URLs. | 236 | return strtr($t, '+/', '-_'); |
237 | $t = str_replace('/','_',$t); | ||
238 | $t = str_replace('=','@',$t); | ||
239 | return $t; | ||
240 | } | 237 | } |
241 | 238 | ||
242 | // In a string, converts urls to clickable links. | 239 | // In a string, converts urls to clickable links. |