Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.57 KB | None | 0 0
  1. diff --git a/staptree.cxx b/staptree.cxx
  2. index cc2127207..277234abc 100644
  3. --- a/staptree.cxx
  4. +++ b/staptree.cxx
  5. @@ -21,6 +21,7 @@
  6.  #include <vector>
  7.  #include <algorithm>
  8.  #include <cstring>
  9. +#include <unordered_map>
  10.  
  11.  using namespace std;
  12.  
  13. @@ -402,13 +403,28 @@ string atvar_op::sym_name ()
  14.  }
  15.  
  16.  
  17. +struct str_pair_hash {
  18. +    template <class T1, class T2>
  19. +    std::size_t operator () (const std::pair<T1,T2> &p) const {
  20. +        auto h1 = std::hash<T1>{}(p.first);
  21. +        auto h2 = std::hash<T2>{}(p.second);
  22. +
  23. +        // Mainly for demonstration purposes, i.e. works but is overly simple
  24. +        // In the real world, use sth. like boost.hash_combine
  25. +        return h1 ^ h2;
  26. +    }
  27. +};
  28. +
  29. +
  30.  // Substring operations like interned_string.find() are repeated a
  31.  // surprising number of times (with nested / widely used tapset emb-C
  32.  // functions), and need to be efficient.  We memoize the search
  33.  // results.
  34.  bool memo_tagged_p (const interned_string& haystack, const string& needle)
  35.  {
  36. -  static map <pair<interned_string,string>,bool> string_find_memoized;
  37. +  static std::unordered_map <pair<interned_string,string>,bool,str_pair_hash>
  38. +    string_find_memoized;
  39. +
  40.    auto key = make_pair(haystack,needle);
  41.  
  42.    auto it = string_find_memoized.find(key);
  43. @@ -417,7 +433,7 @@ bool memo_tagged_p (const interned_string& haystack, const string& needle)
  44.  
  45.    auto findres = haystack.find(needle);
  46.    bool res = (findres != interned_string::npos);
  47. -  string_find_memoized.insert(make_pair(key,res));
  48. +  string_find_memoized[key] = res;
  49.  
  50.    return res;
  51.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement