Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.33 KB | None | 0 0
  1. diff --git a/staptree.cxx b/staptree.cxx
  2. index cc2127207..e50040aff 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. @@ -423,46 +424,61 @@ bool memo_tagged_p (const interned_string& haystack, const string& needle)
  14.  }
  15.  
  16.  
  17. -
  18.  bool
  19. -embedded_expr::tagged_p (const char *tag) const
  20. +embedded_expr::tagged_p (const char *tag)
  21.  {
  22. -  return memo_tagged_p (code, tag);
  23. +  return tagged_p (interned_string (tag));
  24.  }
  25.  
  26.  
  27.  bool
  28. -embedded_expr::tagged_p (const string &tag) const
  29. +embedded_expr::tagged_p (const string &tag)
  30.  {
  31. -  return memo_tagged_p (code, tag);
  32. +  return tagged_p (interned_string (tag));
  33.  }
  34.  
  35.  
  36.  bool
  37. -embedded_expr::tagged_p (const interned_string& tag) const
  38. +embedded_expr::tagged_p (const interned_string& tag)
  39.  {
  40. -  return memo_tagged_p (code, tag);
  41. +  auto it = string_find_memoized.find(tag);
  42. +  if (it != string_find_memoized.end())
  43. +    return it->second;
  44. +
  45. +  auto findres = code.find(tag);
  46. +  bool res = (findres != interned_string::npos);
  47. +  string_find_memoized[tag] = res;
  48. +
  49. +  return res;
  50.  }
  51.  
  52.  
  53.  bool
  54. -embeddedcode::tagged_p (const char *tag) const
  55. +embeddedcode::tagged_p (const char *tag)
  56.  {
  57. -  return memo_tagged_p (code, tag);
  58. +  return tagged_p (interned_string (tag));
  59.  }
  60.  
  61.  
  62.  bool
  63. -embeddedcode::tagged_p (const string &tag) const
  64. +embeddedcode::tagged_p (const string &tag)
  65.  {
  66. -  return memo_tagged_p (code, tag);
  67. +  return tagged_p (interned_string (tag));
  68.  }
  69.  
  70.  
  71.  bool
  72. -embeddedcode::tagged_p (const interned_string& tag) const
  73. +embeddedcode::tagged_p (const interned_string& tag)
  74.  {
  75. -  return memo_tagged_p (code, tag);
  76. +  auto it = string_find_memoized.find(tag);
  77. +  if (it != string_find_memoized.end())
  78. +    return it->second;
  79. +
  80. +  auto findres = code.find(tag);
  81. +  bool res = (findres != interned_string::npos);
  82. +  string_find_memoized[tag] = res;
  83. +
  84. +  return res;
  85.  }
  86.  
  87.  
  88. diff --git a/staptree.h b/staptree.h
  89. index 177879647..892c330bd 100644
  90. --- a/staptree.h
  91. +++ b/staptree.h
  92. @@ -20,6 +20,7 @@
  93.  #include <stdexcept>
  94.  #include <cassert>
  95.  #include <typeinfo>
  96. +#include <unordered_map>
  97.  extern "C" {
  98.  #include <stdint.h>
  99.  }
  100. @@ -184,9 +185,10 @@ struct literal_number: public literal
  101.  struct embedded_expr: public expression
  102.  {
  103.    interned_string code;
  104. -  bool tagged_p (const char *tag) const;
  105. -  bool tagged_p (const std::string &tag) const;
  106. -  bool tagged_p (const interned_string& tag) const;
  107. +  std::unordered_map <interned_string,bool> string_find_memoized;
  108. +  bool tagged_p (const char *tag);
  109. +  bool tagged_p (const std::string &tag);
  110. +  bool tagged_p (const interned_string& tag);
  111.    void print (std::ostream& o) const;
  112.    void visit (visitor* u);
  113.  };
  114. @@ -717,9 +719,10 @@ std::ostream& operator << (std::ostream& o, const statement& k);
  115.  struct embeddedcode: public statement
  116.  {
  117.    interned_string code;
  118. -  bool tagged_p (const char *tag) const;
  119. -  bool tagged_p (const std::string& tag) const;
  120. -  bool tagged_p (const interned_string& tag) const;
  121. +  std::unordered_map <interned_string,bool> string_find_memoized;
  122. +  bool tagged_p (const char *tag);
  123. +  bool tagged_p (const std::string& tag);
  124. +  bool tagged_p (const interned_string& tag);
  125.    void print (std::ostream& o) const;
  126.    void visit (visitor* u);
  127.  };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement