Advertisement
Guest User

Untitled

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