From 1c2260f73ec97e75a4be94fbe88780e77a4d9a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Can=20B=C3=B6l=C3=BCk?= Date: Fri, 21 Aug 2020 08:14:49 +0200 Subject: [PATCH] Remove unnecessary type erasure. --- VTIL-Architecture/trace/cached_tracer.cpp | 79 ++++++++++------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/VTIL-Architecture/trace/cached_tracer.cpp b/VTIL-Architecture/trace/cached_tracer.cpp index fe45ff7..da49f04 100644 --- a/VTIL-Architecture/trace/cached_tracer.cpp +++ b/VTIL-Architecture/trace/cached_tracer.cpp @@ -55,52 +55,6 @@ namespace vtil return result; } - // Declare a predicate for the search of the variable in the cache. - // - function_view predicate; - - // If memory variable: - // - if ( lookup.is_memory() ) - { - predicate = [ & ] ( const cache_entry& pair ) - { - // Key must be of memory type at the same position. - // - if ( !pair.first.is_memory() ) return false; - if ( pair.first.at != lookup.at ) return false; - - // Must be the same pointer and have a larger or equal size. - // - auto& self = lookup.mem(); - auto& other = pair.first.mem(); - return self.decay()->equals( *other.decay() ) && - self.bit_count >= other.bit_count; - }; - } - // If register variable: - // - else - { - fassert( lookup.is_register() ); - predicate = [ & ] ( const cache_entry& pair ) - { - // Key must be of memory type at the same position. - // - if ( !pair.first.is_register() ) return false; - if ( pair.first.at != lookup.at ) return false; - - // Must be the same register and have a larger or equal size. - // - auto& self = lookup.reg(); - auto& other = pair.first.reg(); - return self.flags == other.flags && - self.combined_id == other.combined_id && - self.bit_offset == other.bit_offset && - self.bit_count >= other.bit_count; - }; - } - // Try lookup the exact variable in the map in a fast manner. // std::shared_lock lock{ mtx }; @@ -143,6 +97,39 @@ namespace vtil return result; } + // Declare a predicate for the search of the variable in the cache. + // + auto predicate = [ & ] ( const cache_entry& pair ) + { + // Key must be of same type at the same position. + // + if ( pair.first.is_register() != lookup.is_register() || + pair.first.at != lookup.at ) + return false; + + if ( lookup.is_memory() ) + { + // Must be the same pointer and have a larger or equal size. + // + auto& self = lookup.mem(); + auto& other = pair.first.mem(); + return self.bit_count >= other.bit_count && + self.decay()->equals( *other.decay() ); + } + else + { + // Must be the same register and have a larger or equal size. + // + auto& self = lookup.reg(); + auto& other = pair.first.reg(); + return self.flags == other.flags && + self.combined_id == other.combined_id && + self.bit_offset == other.bit_offset && + self.bit_count >= other.bit_count; + } + }; + + // Search the map, if we find a matching entry shrink and use as the result. // symbolic::expression::reference result;