Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Side by Side Diff: runtime/platform/hashmap.cc

Issue 2418323002: Make fatal out of memory messages uniform. (Closed)
Patch Set: macro Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/platform/assert.h ('k') | runtime/platform/text_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/hashmap.h" 5 #include "platform/hashmap.h"
6 6
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 160
161 return p; 161 return p;
162 } 162 }
163 163
164 164
165 void HashMap::Initialize(uint32_t capacity) { 165 void HashMap::Initialize(uint32_t capacity) {
166 ASSERT(dart::Utils::IsPowerOfTwo(capacity)); 166 ASSERT(dart::Utils::IsPowerOfTwo(capacity));
167 map_ = new Entry[capacity]; 167 map_ = new Entry[capacity];
168 if (map_ == NULL) { 168 if (map_ == NULL) {
169 // TODO(sgjesse): Handle out of memory. 169 OUT_OF_MEMORY();
170 FATAL("Cannot allocate memory for hashmap");
171 return;
172 } 170 }
173 capacity_ = capacity; 171 capacity_ = capacity;
174 occupancy_ = 0; 172 occupancy_ = 0;
175 } 173 }
176 174
177 175
178 void HashMap::Resize() { 176 void HashMap::Resize() {
179 Entry* map = map_; 177 Entry* map = map_;
180 uint32_t n = occupancy_; 178 uint32_t n = occupancy_;
181 179
182 // Allocate larger map. 180 // Allocate larger map.
183 Initialize(capacity_ * 2); 181 Initialize(capacity_ * 2);
184 182
185 // Rehash all current entries. 183 // Rehash all current entries.
186 for (Entry* p = map; n > 0; p++) { 184 for (Entry* p = map; n > 0; p++) {
187 if (p->key != NULL) { 185 if (p->key != NULL) {
188 Lookup(p->key, p->hash, true)->value = p->value; 186 Lookup(p->key, p->hash, true)->value = p->value;
189 n--; 187 n--;
190 } 188 }
191 } 189 }
192 190
193 // Delete old map. 191 // Delete old map.
194 delete[] map; 192 delete[] map;
195 } 193 }
196 194
197 } // namespace dart 195 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/platform/assert.h ('k') | runtime/platform/text_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698