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

Side by Side Diff: src/small-pointer-list.h

Issue 10534006: Remove TLS access for current Zone. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review. Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/scopes.cc ('k') | src/splay-tree.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 26 matching lines...) Expand all
37 37
38 // SmallPointerList is a list optimized for storing no or just a 38 // SmallPointerList is a list optimized for storing no or just a
39 // single value. When more values are given it falls back to ZoneList. 39 // single value. When more values are given it falls back to ZoneList.
40 // 40 //
41 // The interface tries to be as close to List from list.h as possible. 41 // The interface tries to be as close to List from list.h as possible.
42 template <typename T> 42 template <typename T>
43 class SmallPointerList { 43 class SmallPointerList {
44 public: 44 public:
45 SmallPointerList() : data_(kEmptyTag) {} 45 SmallPointerList() : data_(kEmptyTag) {}
46 46
47 explicit SmallPointerList(int capacity) : data_(kEmptyTag) { 47 SmallPointerList(int capacity, Zone* zone) : data_(kEmptyTag) {
48 Reserve(capacity); 48 Reserve(capacity, zone);
49 } 49 }
50 50
51 void Reserve(int capacity) { 51 void Reserve(int capacity, Zone* zone) {
52 if (capacity < 2) return; 52 if (capacity < 2) return;
53 if ((data_ & kTagMask) == kListTag) { 53 if ((data_ & kTagMask) == kListTag) {
54 if (list()->capacity() >= capacity) return; 54 if (list()->capacity() >= capacity) return;
55 int old_length = list()->length(); 55 int old_length = list()->length();
56 list()->AddBlock(NULL, capacity - list()->capacity()); 56 list()->AddBlock(NULL, capacity - list()->capacity(), zone);
57 list()->Rewind(old_length); 57 list()->Rewind(old_length);
58 return; 58 return;
59 } 59 }
60 PointerList* list = new PointerList(capacity); 60 PointerList* list = new(zone) PointerList(capacity, zone);
61 if ((data_ & kTagMask) == kSingletonTag) { 61 if ((data_ & kTagMask) == kSingletonTag) {
62 list->Add(single_value()); 62 list->Add(single_value(), zone);
63 } 63 }
64 ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment)); 64 ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment));
65 data_ = reinterpret_cast<intptr_t>(list) | kListTag; 65 data_ = reinterpret_cast<intptr_t>(list) | kListTag;
66 } 66 }
67 67
68 void Clear() { 68 void Clear() {
69 data_ = kEmptyTag; 69 data_ = kEmptyTag;
70 } 70 }
71 71
72 void Sort() { 72 void Sort() {
73 if ((data_ & kTagMask) == kListTag) { 73 if ((data_ & kTagMask) == kListTag) {
74 list()->Sort(compare_value); 74 list()->Sort(compare_value);
75 } 75 }
76 } 76 }
77 77
78 bool is_empty() const { return length() == 0; } 78 bool is_empty() const { return length() == 0; }
79 79
80 int length() const { 80 int length() const {
81 if ((data_ & kTagMask) == kEmptyTag) return 0; 81 if ((data_ & kTagMask) == kEmptyTag) return 0;
82 if ((data_ & kTagMask) == kSingletonTag) return 1; 82 if ((data_ & kTagMask) == kSingletonTag) return 1;
83 return list()->length(); 83 return list()->length();
84 } 84 }
85 85
86 void Add(T* pointer) { 86 void Add(T* pointer, Zone* zone) {
87 ASSERT(IsAligned(reinterpret_cast<intptr_t>(pointer), kPointerAlignment)); 87 ASSERT(IsAligned(reinterpret_cast<intptr_t>(pointer), kPointerAlignment));
88 if ((data_ & kTagMask) == kEmptyTag) { 88 if ((data_ & kTagMask) == kEmptyTag) {
89 data_ = reinterpret_cast<intptr_t>(pointer) | kSingletonTag; 89 data_ = reinterpret_cast<intptr_t>(pointer) | kSingletonTag;
90 return; 90 return;
91 } 91 }
92 if ((data_ & kTagMask) == kSingletonTag) { 92 if ((data_ & kTagMask) == kSingletonTag) {
93 PointerList* list = new PointerList(2); 93 PointerList* list = new(zone) PointerList(2, zone);
94 list->Add(single_value()); 94 list->Add(single_value(), zone);
95 list->Add(pointer); 95 list->Add(pointer, zone);
96 ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment)); 96 ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment));
97 data_ = reinterpret_cast<intptr_t>(list) | kListTag; 97 data_ = reinterpret_cast<intptr_t>(list) | kListTag;
98 return; 98 return;
99 } 99 }
100 list()->Add(pointer); 100 list()->Add(pointer, zone);
101 } 101 }
102 102
103 // Note: returns T* and not T*& (unlike List from list.h). 103 // Note: returns T* and not T*& (unlike List from list.h).
104 // This makes the implementation simpler and more const correct. 104 // This makes the implementation simpler and more const correct.
105 T* at(int i) const { 105 T* at(int i) const {
106 ASSERT((data_ & kTagMask) != kEmptyTag); 106 ASSERT((data_ & kTagMask) != kEmptyTag);
107 if ((data_ & kTagMask) == kSingletonTag) { 107 if ((data_ & kTagMask) == kSingletonTag) {
108 ASSERT(i == 0); 108 ASSERT(i == 0);
109 return single_value(); 109 return single_value();
110 } 110 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 190
191 intptr_t data_; 191 intptr_t data_;
192 192
193 DISALLOW_COPY_AND_ASSIGN(SmallPointerList); 193 DISALLOW_COPY_AND_ASSIGN(SmallPointerList);
194 }; 194 };
195 195
196 } } // namespace v8::internal 196 } } // namespace v8::internal
197 197
198 #endif // V8_SMALL_POINTER_LIST_H_ 198 #endif // V8_SMALL_POINTER_LIST_H_
OLDNEW
« no previous file with comments | « src/scopes.cc ('k') | src/splay-tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698