From 767a5e1281ed436a11af90e0249bd59a5fbd40c8 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sun, 16 Jul 2017 20:56:58 +0200 Subject: [PATCH] dev-cache: avoid hashing same data again Before hashing device again with path, check if it's not already hashed. TODO: maybe bigger chunk of executed code might be actually skipped. --- lib/device/dev-cache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 06d44ce2b..9a4dbc90a 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -706,6 +706,12 @@ static int _insert_dev(const char *path, dev_t d) } } + if (dm_hash_lookup(_cache.names, path) == dev) { + /* Hash already has matching entry present */ + log_debug("Path already cached %s.", path); + return 1; + } + if (!(path_copy = dm_pool_strdup(_cache.mem, path))) { log_error("Failed to duplicate path string."); return 0;