symboltable_std_string_overhead.diff

pasted by tilman [options]

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<table class="sourcetable"><tr><td class="linenos"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91</pre></td><td class="code"><div class="source"><pre>This makes SymbolTable::lookup drop from 8% to 2% in a profile run of the
VM booting process (tested with a hello world-like script).

<span class="gh">diff --git a/vm/symboltable.cpp b/vm/symboltable.cpp</span>
index f4a8b6a..8f870b4 100644
<span class="gd">--- a/vm/symboltable.cpp</span>
<span class="gi">+++ b/vm/symboltable.cpp</span>
<span class="gu">@@ -49,36 +49,34 @@ namespace rubinius {</span>
     return strings.size() - 1;
   }
 
<span class="gd">-  Symbol* SymbolTable::lookup(STATE, std::string str) {</span>
<span class="gi">+  Symbol* SymbolTable::lookup(STATE, const char* str) {</span>
     size_t sym;
 
<span class="gd">-    if(str.size() == 0) {</span>
<span class="gi">+    if(*str == 0) {</span>
       Exception::argument_error(state, &quot;Cannot create a symbol from an empty string&quot;);
     }
 
<span class="gd">-    hashval hash = String::hash_str((unsigned char*)str.c_str(), str.size());</span>
<span class="gi">+    hashval hash = String::hash_str((unsigned char*)str, strlen(str));</span>
 
     SymbolMap::iterator entry = symbols.find(hash);
     if(entry == symbols.end()) {
<span class="gd">-      sym = add(str);</span>
<span class="gi">+      sym = add(std::string(str));</span>
       SymbolIds v(1, sym);
       symbols[hash] = v;
     } else {
       SymbolIds&amp; v = entry-&gt;second;
       for(SymbolIds::iterator i = v.begin(); i != v.end(); i++) {
<span class="gd">-        if(strings[*i] == str) return Symbol::from_index(state, *i);</span>
<span class="gi">+        std::string&amp; s = strings[*i];</span>
<span class="gi">+</span>
<span class="gi">+        if(!strcmp(s.c_str(), str)) return Symbol::from_index(state, *i);</span>
       }
<span class="gd">-      sym = add(str);</span>
<span class="gi">+      sym = add(std::string(str));</span>
       v.push_back(sym);
     }
 
     return Symbol::from_index(state, sym);
   }
 
<span class="gd">-  Symbol* SymbolTable::lookup(STATE, const char* str) {</span>
<span class="gd">-    return lookup(state, std::string(str));</span>
<span class="gd">-  }</span>
<span class="gd">-</span>
   Symbol* SymbolTable::lookup(STATE, String* str) {
     if(str-&gt;nil_p()) {
       Exception::argument_error(state, &quot;Cannot look up Symbol from nil&quot;);
<span class="gh">diff --git a/vm/symboltable.hpp b/vm/symboltable.hpp</span>
index d70276b..e8bf6df 100644
<span class="gd">--- a/vm/symboltable.hpp</span>
<span class="gi">+++ b/vm/symboltable.hpp</span>
<span class="gu">@@ -51,7 +51,6 @@ namespace rubinius {</span>
     typedef std::vector&lt;Kind&gt; SymbolKinds;
 
   public:
<span class="gd">-    Symbol* lookup(STATE, std::string str);</span>
     Symbol* lookup(STATE, const char* str);
     Symbol* lookup(STATE, String* str);
     String* lookup_string(STATE, const Symbol* sym);
<span class="gh">diff --git a/vm/vm.cpp b/vm/vm.cpp</span>
index e9ac028..b929ef8 100644
<span class="gd">--- a/vm/vm.cpp</span>
<span class="gi">+++ b/vm/vm.cpp</span>
<span class="gu">@@ -196,10 +196,6 @@ namespace rubinius {</span>
     return symbols.lookup(this, str);
   }
 
<span class="gd">-  Symbol* VM::symbol(std::string str) {</span>
<span class="gd">-    return symbols.lookup(this, str);</span>
<span class="gd">-  }</span>
<span class="gd">-</span>
   void type_assert(STATE, Object* obj, object_type type, const char* reason) {
     if((obj-&gt;reference_p() &amp;&amp; obj-&gt;type_id() != type)
         || (type == FixnumType &amp;&amp; !obj-&gt;fixnum_p())) {
<span class="gh">diff --git a/vm/vm.hpp b/vm/vm.hpp</span>
index aeda91c..d6742e2 100644
<span class="gd">--- a/vm/vm.hpp</span>
<span class="gi">+++ b/vm/vm.hpp</span>
<span class="gu">@@ -267,7 +267,6 @@ namespace rubinius {</span>
 
     Symbol* symbol(const char* str);
     Symbol* symbol(String* str);
<span class="gd">-    Symbol* symbol(std::string str);</span>
 
     TypeInfo* find_type(int type);
 
</pre></div>
</td></tr></table>