Skip to content

Commit

Permalink
Switch to the faster FNV-1a hash for compose hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Mar 14, 2014
1 parent e4b656d commit ad7b634
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 113 deletions.
17 changes: 8 additions & 9 deletions imp/js/compose-dimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var DimpCompose = {
})
}),
knl: {},
seed: 3,

getCacheElt: function()
{
Expand Down Expand Up @@ -702,11 +701,10 @@ var DimpCompose = {
return;
}

hdrs = murmurhash3(
hdrs = IMP_JS.fnv_1a(
[$('to', 'cc', 'bcc', 'subject').compact().invoke('getValue'),
$('attach_list').select('SPAN.attachName').pluck('textContent')
].flatten().join('\0'),
this.seed
].flatten().join('\0')
);

if (Object.isUndefined(this.hash_hdrs)) {
Expand All @@ -729,15 +727,16 @@ var DimpCompose = {

msgHash: function()
{
return murmurhash3(ImpComposeBase.editor_on ? this.rte.getData() : $F('composeMessage'), this.seed);
return IMP_JS.fnv_1a(
ImpComposeBase.editor_on ? this.rte.getData() : $F('composeMessage')
);
},

sigHash: function()
{
if (!$('signature')) {
return 0;
}
return murmurhash3(ImpComposeBase.editor_on ? ImpComposeBase.rte.getData() : $F('signature'), this.seed);
return $('signature')
? IMP_JS.fnv_1a(ImpComposeBase.editor_on ? ImpComposeBase.rte.getData() : $F('signature'))
: 0;
},

updateSigHash: function()
Expand Down
12 changes: 6 additions & 6 deletions imp/js/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var ImpCompose = {
// sc_submit, sm_check, skip_spellcheck, spellcheck, text

display_unload_warning: true,
seed: 3,

confirmCancel: function(discard, e)
{
Expand Down Expand Up @@ -147,7 +146,9 @@ var ImpCompose = {
CKEDITOR.instances.composeMessage.updateElement();
}

cur_msg = murmurhash3($('to', 'cc', 'bcc', 'subject').compact().invoke('getValue').join('\0') + $F('composeMessage'), this.seed);
cur_msg = IMP_JS.fnv_1a(
$('to', 'cc', 'bcc', 'subject').compact().invoke('getValue').join('\0') + $F('composeMessage')
);
if (this.last_msg && curr_hash != this.last_msg) {
// Use an AJAX submit here so that the page doesn't reload.
$('actionID').setValue(actionID);
Expand Down Expand Up @@ -228,10 +229,9 @@ var ImpCompose = {

sigHash: function()
{
if (!$('signature')) {
return 0;
}
return murmurhash3(ImpComposeBase.editor_on ? ImpComposeBase.rte.getData() : $F('signature'), this.seed);
return $('signature')
? IMP_JS.fnv_1a(ImpComposeBase.editor_on ? ImpComposeBase.rte.getData() : $F('signature'))
: 0;
},

updateSigHash: function()
Expand Down
93 changes: 0 additions & 93 deletions imp/js/external/murmurhash3.js

This file was deleted.

13 changes: 13 additions & 0 deletions imp/js/imp.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ var IMP_JS = {
if (w || h) {
win.resizeBy(w, h);
}
},

fnv_1a: function(str)
{
var i, l,
hash = 0x811c9dc5;

for (i = 0, l = str.length; i < l; ++i) {
hash ^= str.charCodeAt(i);
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
}

return hash >>> 0;
}

};
2 changes: 1 addition & 1 deletion imp/lib/Basic/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ protected function _init()

$page_output->addScriptPackage('IMP_Script_Package_ComposeBase');
$page_output->addScriptFile('compose.js');
$page_output->addScriptFile('external/murmurhash3.js');
$page_output->addScriptFile('imp.js');
$page_output->addInlineJsVars($js_vars);
if (!$redirect) {
$imp_ui->addIdentityJs();
Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Dynamic/Compose/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function compose(IMP_Dynamic_Base $base, array $args = array())
$page_output->addScriptPackage('IMP_Script_Package_ComposeBase');
$page_output->addScriptFile('compose-dimp.js');
$page_output->addScriptFile('draghandler.js');
$page_output->addScriptFile('external/murmurhash3.js');
$page_output->addScriptFile('imp.js');

if (!$prefs->isLocked('default_encrypt') &&
($prefs->getValue('use_pgp') || $prefs->getValue('use_smime'))) {
Expand Down
4 changes: 1 addition & 3 deletions imp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>yes</active>
</lead>
<date>2014-03-12</date>
<date>2014-03-13</date>
<version>
<release>6.2.0</release>
<api>6.2.0</api>
Expand Down Expand Up @@ -109,7 +109,6 @@
</dir> <!-- /js/ckeditor -->
<dir name="external">
<file name="base64.js" role="horde" />
<file name="murmurhash3.js" role="horde" />
</dir> <!-- /js/external -->
<dir name="jquery.mobile">
<dir name="plugins">
Expand Down Expand Up @@ -1579,7 +1578,6 @@
<install as="imp/js/ckeditor/pasteattachment.js" name="js/ckeditor/pasteattachment.js" />
<install as="imp/js/ckeditor/pasteignore.js" name="js/ckeditor/pasteignore.js" />
<install as="imp/js/external/base64.js" name="js/external/base64.js" />
<install as="imp/js/external/murmurhash3.js" name="js/external/murmurhash3.js" />
<install as="imp/js/jquery.mobile/plugins/listviewtaphold.js" name="js/jquery.mobile/plugins/listviewtaphold.js" />
<install as="imp/js/jquery.mobile/plugins/textchange.js" name="js/jquery.mobile/plugins/textchange.js" />
<install as="imp/lib/.htaccess" name="lib/.htaccess" />
Expand Down

0 comments on commit ad7b634

Please sign in to comment.