OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 CHECK_EQ(2, ordered_map->NumberOfBuckets()); | 111 CHECK_EQ(2, ordered_map->NumberOfBuckets()); |
112 CHECK_EQ(0, ordered_map->NumberOfElements()); | 112 CHECK_EQ(0, ordered_map->NumberOfElements()); |
113 CHECK_EQ(0, ordered_map->NumberOfDeletedElements()); | 113 CHECK_EQ(0, ordered_map->NumberOfDeletedElements()); |
114 | 114 |
115 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 115 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
116 Handle<JSObject> obj = factory->NewJSObjectFromMap(map); | 116 Handle<JSObject> obj = factory->NewJSObjectFromMap(map); |
117 Handle<JSObject> val = factory->NewJSObjectFromMap(map); | 117 Handle<JSObject> val = factory->NewJSObjectFromMap(map); |
118 CHECK(ordered_map->Lookup(obj)->IsTheHole()); | 118 CHECK(ordered_map->Lookup(obj)->IsTheHole()); |
119 ordered_map = OrderedHashMap::Put(ordered_map, obj, val); | 119 ordered_map = OrderedHashMap::Put(ordered_map, obj, val); |
120 CHECK_EQ(1, ordered_map->NumberOfElements()); | 120 CHECK_EQ(1, ordered_map->NumberOfElements()); |
121 CHECK(ordered_map->Lookup(obj)->SameValue(*val)); | 121 Object* lookup = ordered_map->Lookup(obj); |
| 122 CHECK(lookup->SameValue(*val)); |
122 bool was_present = false; | 123 bool was_present = false; |
123 ordered_map = OrderedHashMap::Remove(ordered_map, obj, &was_present); | 124 ordered_map = OrderedHashMap::Remove(ordered_map, obj, &was_present); |
124 CHECK(was_present); | 125 CHECK(was_present); |
125 CHECK_EQ(0, ordered_map->NumberOfElements()); | 126 CHECK_EQ(0, ordered_map->NumberOfElements()); |
126 CHECK(ordered_map->Lookup(obj)->IsTheHole()); | 127 CHECK(ordered_map->Lookup(obj)->IsTheHole()); |
127 | 128 |
128 // Test for collisions/chaining | 129 // Test for collisions/chaining |
129 Handle<JSObject> obj1 = factory->NewJSObjectFromMap(map); | 130 Handle<JSObject> obj1 = factory->NewJSObjectFromMap(map); |
130 Handle<JSObject> obj2 = factory->NewJSObjectFromMap(map); | 131 Handle<JSObject> obj2 = factory->NewJSObjectFromMap(map); |
131 Handle<JSObject> obj3 = factory->NewJSObjectFromMap(map); | 132 Handle<JSObject> obj3 = factory->NewJSObjectFromMap(map); |
132 Handle<JSObject> val1 = factory->NewJSObjectFromMap(map); | 133 Handle<JSObject> val1 = factory->NewJSObjectFromMap(map); |
133 Handle<JSObject> val2 = factory->NewJSObjectFromMap(map); | 134 Handle<JSObject> val2 = factory->NewJSObjectFromMap(map); |
134 Handle<JSObject> val3 = factory->NewJSObjectFromMap(map); | 135 Handle<JSObject> val3 = factory->NewJSObjectFromMap(map); |
135 ordered_map = OrderedHashMap::Put(ordered_map, obj1, val1); | 136 ordered_map = OrderedHashMap::Put(ordered_map, obj1, val1); |
136 ordered_map = OrderedHashMap::Put(ordered_map, obj2, val2); | 137 ordered_map = OrderedHashMap::Put(ordered_map, obj2, val2); |
137 ordered_map = OrderedHashMap::Put(ordered_map, obj3, val3); | 138 ordered_map = OrderedHashMap::Put(ordered_map, obj3, val3); |
138 CHECK_EQ(3, ordered_map->NumberOfElements()); | 139 CHECK_EQ(3, ordered_map->NumberOfElements()); |
139 CHECK(ordered_map->Lookup(obj1)->SameValue(*val1)); | 140 lookup = ordered_map->Lookup(obj1); |
140 CHECK(ordered_map->Lookup(obj2)->SameValue(*val2)); | 141 CHECK(lookup->SameValue(*val1)); |
141 CHECK(ordered_map->Lookup(obj3)->SameValue(*val3)); | 142 lookup = ordered_map->Lookup(obj2); |
| 143 CHECK(lookup->SameValue(*val2)); |
| 144 lookup = ordered_map->Lookup(obj3); |
| 145 CHECK(lookup->SameValue(*val3)); |
142 | 146 |
143 // Test growth | 147 // Test growth |
144 ordered_map = OrderedHashMap::Put(ordered_map, obj, val); | 148 ordered_map = OrderedHashMap::Put(ordered_map, obj, val); |
145 Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map); | 149 Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map); |
146 Handle<JSObject> val4 = factory->NewJSObjectFromMap(map); | 150 Handle<JSObject> val4 = factory->NewJSObjectFromMap(map); |
147 ordered_map = OrderedHashMap::Put(ordered_map, obj4, val4); | 151 ordered_map = OrderedHashMap::Put(ordered_map, obj4, val4); |
148 CHECK(ordered_map->Lookup(obj)->SameValue(*val)); | 152 lookup = ordered_map->Lookup(obj); |
149 CHECK(ordered_map->Lookup(obj1)->SameValue(*val1)); | 153 CHECK(lookup->SameValue(*val)); |
150 CHECK(ordered_map->Lookup(obj2)->SameValue(*val2)); | 154 lookup = ordered_map->Lookup(obj1); |
151 CHECK(ordered_map->Lookup(obj3)->SameValue(*val3)); | 155 CHECK(lookup->SameValue(*val1)); |
152 CHECK(ordered_map->Lookup(obj4)->SameValue(*val4)); | 156 lookup = ordered_map->Lookup(obj2); |
| 157 CHECK(lookup->SameValue(*val2)); |
| 158 lookup = ordered_map->Lookup(obj3); |
| 159 CHECK(lookup->SameValue(*val3)); |
| 160 lookup = ordered_map->Lookup(obj4); |
| 161 CHECK(lookup->SameValue(*val4)); |
153 CHECK_EQ(5, ordered_map->NumberOfElements()); | 162 CHECK_EQ(5, ordered_map->NumberOfElements()); |
154 CHECK_EQ(4, ordered_map->NumberOfBuckets()); | 163 CHECK_EQ(4, ordered_map->NumberOfBuckets()); |
155 | 164 |
156 // Test shrinking | 165 // Test shrinking |
157 ordered_map = OrderedHashMap::Remove(ordered_map, obj, &was_present); | 166 ordered_map = OrderedHashMap::Remove(ordered_map, obj, &was_present); |
158 CHECK(was_present); | 167 CHECK(was_present); |
159 ordered_map = OrderedHashMap::Remove(ordered_map, obj1, &was_present); | 168 ordered_map = OrderedHashMap::Remove(ordered_map, obj1, &was_present); |
160 CHECK(was_present); | 169 CHECK(was_present); |
161 ordered_map = OrderedHashMap::Remove(ordered_map, obj2, &was_present); | 170 ordered_map = OrderedHashMap::Remove(ordered_map, obj2, &was_present); |
162 CHECK(was_present); | 171 CHECK(was_present); |
163 ordered_map = OrderedHashMap::Remove(ordered_map, obj3, &was_present); | 172 ordered_map = OrderedHashMap::Remove(ordered_map, obj3, &was_present); |
164 CHECK(was_present); | 173 CHECK(was_present); |
165 CHECK_EQ(1, ordered_map->NumberOfElements()); | 174 CHECK_EQ(1, ordered_map->NumberOfElements()); |
166 CHECK_EQ(2, ordered_map->NumberOfBuckets()); | 175 CHECK_EQ(2, ordered_map->NumberOfBuckets()); |
167 } | 176 } |
168 | 177 |
169 | 178 |
170 } | 179 } |
OLD | NEW |