mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-23 07:38:16 +00:00
plugin: Don't do lossy shift on hash
In plugin is responsible for calculating a hash of the dependencies in order to determine if the cache should be invalidated or not. Currently, the hash combining method removes a bit of the original have before combining with an addition. As we use 32bits for our hash and shift 1 bit for each file and directory, that resulting hash only account for the last 32 files. And is more affected by the last file. Rotating technique (shifting, and adding back the ending bit), can be use to make the addition non-commutative. In a way that different order gives different hashes. In this case, I don't preserve this behaviour because the order in which the files are provided by the OS is irrelevant. In most cases, the XOR operation is used to combine hashes. In this code we use the addition. I decided to preserve the addition because we make use of non-random hash ((guint) -1) in the algorithm for matching files that are not really part of the hash (symlinks, special files). Doing successive XOR on this value, will simply switch from full ones, to full zero. The XOR used with whitelist has been preserved as it's based on a fairly randomized hash (g_str_hash). https://bugzilla.gnome.org/show_bug.cgi?id=758078
This commit is contained in:
parent
7e2aae7942
commit
446b3e6ddc
1 changed files with 3 additions and 4 deletions
|
@ -440,7 +440,7 @@ priv_gst_plugin_loading_get_whitelist_hash (void)
|
|||
gchar **w;
|
||||
|
||||
for (w = _plugin_loading_whitelist; *w != NULL; ++w)
|
||||
hash = (hash << 1) ^ g_str_hash (*w);
|
||||
hash ^= g_str_hash (*w);
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
@ -1575,7 +1575,7 @@ gst_plugin_ext_dep_scan_dir_and_match_names (GstPlugin * plugin,
|
|||
continue;
|
||||
}
|
||||
|
||||
hash = (hash + fhash) << 1;
|
||||
hash = hash + fhash;
|
||||
g_free (full_path);
|
||||
}
|
||||
|
||||
|
@ -1617,7 +1617,7 @@ gst_plugin_ext_dep_scan_path_with_filenames (GstPlugin * plugin,
|
|||
fhash = gst_plugin_ext_dep_get_hash_from_stat_entry (&s);
|
||||
GST_LOG_OBJECT (plugin, "stat: %s (result: %08x)", full_path, fhash);
|
||||
}
|
||||
hash = (hash + fhash) << 1;
|
||||
hash += fhash;
|
||||
g_free (full_path);
|
||||
}
|
||||
} else {
|
||||
|
@ -1661,7 +1661,6 @@ gst_plugin_ext_dep_get_stat_hash (GstPlugin * plugin, GstPluginDep * dep)
|
|||
while ((path = g_queue_pop_head (&scan_paths))) {
|
||||
scan_hash += gst_plugin_ext_dep_scan_path_with_filenames (plugin, path,
|
||||
(const gchar **) dep->names, dep->flags);
|
||||
scan_hash = scan_hash << 1;
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue