Skip to content

Commit

Permalink
Use more efficient hashing algorithm when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 12, 2014
1 parent 71f4745 commit 0a0bf27
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 4 additions & 1 deletion imp/lib/Contents/View.php
Expand Up @@ -290,7 +290,10 @@ public function printAttach($id)
$cache_list[] = $val;
$cache_list[] = filemtime($val);
}
$cache_id = hash('sha1', implode('', $cache_list));
$cache_id = 'imp_printcss_' . hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
implode('|', $cache_list)
);

if (($style = $cache_ob->get($cache_id, 0)) === false) {
try {
Expand Down
5 changes: 4 additions & 1 deletion imp/lib/Dynamic/Base.php
Expand Up @@ -137,7 +137,10 @@ protected function _addBaseVars()

// Other variables
'disable_compose' => !IMP_Compose::canCompose(),
'pref_prefix' => base64_encode(pack('H*', hash('sha1', $registry->getAuth() . '|' . $_SERVER['SERVER_NAME'])))
'pref_prefix' => hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
$registry->getAuth() . '|' . $_SERVER['SERVER_NAME']
)
));

/* Context menu definitions.
Expand Down
5 changes: 4 additions & 1 deletion imp/lib/Factory/ComposeAtc.php
Expand Up @@ -70,7 +70,10 @@ public function create($user = null, $id = null, $type = null)
return new $classname($user);
}

$sig = hash('sha1', serialize(array($user, $id)));
$sig = hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
implode('|', array($user, $id))
);

if (!isset($this->_instances[$sig])) {
$this->_instances[$sig] = new $classname($user, $id);
Expand Down
16 changes: 11 additions & 5 deletions imp/lib/Prefs/Special/Flag.php
Expand Up @@ -63,7 +63,10 @@ public function display(Horde_Core_Prefs_Ui $ui)
$out = array();
$flaglist = $injector->getInstance('IMP_Flags')->getList();
foreach ($flaglist as $val) {
$hash = hash('sha1', $val->id);
$hash = hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
$val->id
);
$bgid = 'bg_' . $hash;
$color = $val->bgdefault ? '' : $val->bgcolor;
$tmp = array();
Expand Down Expand Up @@ -107,11 +110,14 @@ public function update(Horde_Core_Prefs_Ui $ui)
// actions.
$update = false;
foreach ($imp_flags->getList() as $val) {
$sha1 = hash('sha1', $val->id);
$hash = hash(
(PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
$val->id
);

switch ($ui->vars->flag_action) {
case 'delete':
if ($ui->vars->flag_data == ('bg_' . $sha1)) {
if ($ui->vars->flag_data == ('bg_' . $hash)) {
unset($imp_flags[$val->id]);
$notification->push(sprintf(_("Deleted flag \"%s\"."), $val->label), 'horde.success');
}
Expand All @@ -120,15 +126,15 @@ public function update(Horde_Core_Prefs_Ui $ui)
default:
/* Change labels for user-defined flags. */
if ($val instanceof IMP_Flag_User) {
$label = $ui->vars->get('label_' . $sha1);
$label = $ui->vars->get('label_' . $hash);
if (strlen($label) && ($label != $val->label)) {
$imp_flags->updateFlag($val->id, 'label', $label);
$update = true;
}
}

/* Change background for all flags. */
$bg = strtolower($ui->vars->get('bg_' . $sha1));
$bg = strtolower($ui->vars->get('bg_' . $hash));
if ($bg != $val->bgcolor) {
$imp_flags->updateFlag($val->id, 'bgcolor', $bg);
$update = true;
Expand Down

0 comments on commit 0a0bf27

Please sign in to comment.