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

Side by Side Diff: runtime/vm/weak_table.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 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/vm/weak_code.cc ('k') | runtime/vm/zone.h » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/weak_table.h" 5 #include "vm/weak_table.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/raw_object.h" 8 #include "vm/raw_object.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 11 matching lines...) Expand all
22 "Reached impossible state of having more weak table entries" 22 "Reached impossible state of having more weak table entries"
23 " than memory available for heap objects."); 23 " than memory available for heap objects.");
24 } 24 }
25 } 25 }
26 if (result < kMinSize) { 26 if (result < kMinSize) {
27 result = kMinSize; 27 result = kMinSize;
28 } 28 }
29 return result; 29 return result;
30 } 30 }
31 31
32
33 void WeakTable::SetValue(RawObject* key, intptr_t val) { 32 void WeakTable::SetValue(RawObject* key, intptr_t val) {
34 intptr_t mask = size() - 1; 33 intptr_t mask = size() - 1;
35 intptr_t idx = Hash(key) & mask; 34 intptr_t idx = Hash(key) & mask;
36 intptr_t empty_idx = -1; 35 intptr_t empty_idx = -1;
37 RawObject* obj = ObjectAt(idx); 36 RawObject* obj = ObjectAt(idx);
38 37
39 while (obj != NULL) { 38 while (obj != NULL) {
40 if (obj == key) { 39 if (obj == key) {
41 SetValueAt(idx, val); 40 SetValueAt(idx, val);
42 return; 41 return;
(...skipping 25 matching lines...) Expand all
68 // Update the counts. 67 // Update the counts.
69 set_used(used() + 1); 68 set_used(used() + 1);
70 set_count(count() + 1); 69 set_count(count() + 1);
71 70
72 // Rehash if needed to ensure that there are empty slots available. 71 // Rehash if needed to ensure that there are empty slots available.
73 if (used_ >= limit()) { 72 if (used_ >= limit()) {
74 Rehash(); 73 Rehash();
75 } 74 }
76 } 75 }
77 76
78
79 void WeakTable::Reset() { 77 void WeakTable::Reset() {
80 intptr_t* old_data = data_; 78 intptr_t* old_data = data_;
81 used_ = 0; 79 used_ = 0;
82 count_ = 0; 80 count_ = 0;
83 size_ = kMinSize; 81 size_ = kMinSize;
84 data_ = reinterpret_cast<intptr_t*>(calloc(size_, kEntrySize * kWordSize)); 82 data_ = reinterpret_cast<intptr_t*>(calloc(size_, kEntrySize * kWordSize));
85 free(old_data); 83 free(old_data);
86 } 84 }
87 85
88
89 void WeakTable::Rehash() { 86 void WeakTable::Rehash() {
90 intptr_t old_size = size(); 87 intptr_t old_size = size();
91 intptr_t* old_data = data_; 88 intptr_t* old_data = data_;
92 89
93 intptr_t new_size = SizeFor(count(), size()); 90 intptr_t new_size = SizeFor(count(), size());
94 ASSERT(Utils::IsPowerOfTwo(new_size)); 91 ASSERT(Utils::IsPowerOfTwo(new_size));
95 intptr_t* new_data = 92 intptr_t* new_data =
96 reinterpret_cast<intptr_t*>(calloc(new_size, kEntrySize * kWordSize)); 93 reinterpret_cast<intptr_t*>(calloc(new_size, kEntrySize * kWordSize));
97 94
98 intptr_t mask = new_size - 1; 95 intptr_t mask = new_size - 1;
(...skipping 18 matching lines...) Expand all
117 // We should only have used valid entries. 114 // We should only have used valid entries.
118 ASSERT(used() == count()); 115 ASSERT(used() == count());
119 116
120 // Switch to using the newly allocated backing store. 117 // Switch to using the newly allocated backing store.
121 size_ = new_size; 118 size_ = new_size;
122 data_ = new_data; 119 data_ = new_data;
123 free(old_data); 120 free(old_data);
124 } 121 }
125 122
126 } // namespace dart 123 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/weak_code.cc ('k') | runtime/vm/zone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698