Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.30 KB | None | 0 0
  1. diff --git a/staptree.cxx b/staptree.cxx
  2. index cc2127207..e311e0173 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 (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. +  auto it = string_find_memoized.find(tag);
  33. +  if (it != string_find_memoized.end())
  34. +    return it->second;
  35. +
  36. +  auto findres = code.find(tag);
  37. +  bool res = (findres != interned_string::npos);
  38. +  string_find_memoized[tag] = res;
  39. +
  40. +  return res;
  41.  }
  42.  
  43.  
  44.  bool
  45. -embedded_expr::tagged_p (const interned_string& tag) const
  46. +embedded_expr::tagged_p (const interned_string& tag)
  47.  {
  48. -  return memo_tagged_p (code, tag);
  49. +  return tagged_p (tag.to_string ());
  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 (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. +  auto it = string_find_memoized.find(tag);
  68. +  if (it != string_find_memoized.end())
  69. +    return it->second;
  70. +
  71. +  auto findres = code.find(tag);
  72. +  bool res = (findres != interned_string::npos);
  73. +  string_find_memoized[tag] = res;
  74. +
  75. +  return res;
  76.  }
  77.  
  78.  
  79.  bool
  80. -embeddedcode::tagged_p (const interned_string& tag) const
  81. +embeddedcode::tagged_p (const interned_string& tag)
  82.  {
  83. -  return memo_tagged_p (code, tag);
  84. +  return tagged_p (tag.to_string ());
  85.  }
  86.  
  87.  
  88. diff --git a/staptree.h b/staptree.h
  89. index 177879647..efc06b265 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 <std::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 <std::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