Changeset 2789 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 20, 2002, 2:59:04 PM (23 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r2788 r2789 1 2002-11-20 Darin Adler <[email protected]> 2 3 * kjs/types.cpp: Keep ref count for the whole lists of nodes. 4 Doesn't speed things up much, less than 1%. 5 1 6 2002-11-20 Maciej Stachowiak <[email protected]> 2 7 -
trunk/JavaScriptCore/ChangeLog-2002-12-03
r2788 r2789 1 2002-11-20 Darin Adler <[email protected]> 2 3 * kjs/types.cpp: Keep ref count for the whole lists of nodes. 4 Doesn't speed things up much, less than 1%. 5 1 6 2002-11-20 Maciej Stachowiak <[email protected]> 2 7 -
trunk/JavaScriptCore/ChangeLog-2003-10-25
r2788 r2789 1 2002-11-20 Darin Adler <[email protected]> 2 3 * kjs/types.cpp: Keep ref count for the whole lists of nodes. 4 Doesn't speed things up much, less than 1%. 5 1 6 2002-11-20 Maciej Stachowiak <[email protected]> 2 7 -
trunk/JavaScriptCore/kjs/types.cpp
r2777 r2789 37 37 #include "nodes.h" 38 38 39 using namespace KJS;40 41 39 namespace KJS { 42 40 43 class ListNode { 44 friend class List; 45 friend class ListIterator; 46 protected: 41 struct ListNode { 47 42 ListNode(const Value &val, ListNode *p, ListNode *n) 48 : member(val.imp()), prev(p), next(n) { };43 : member(val.imp()), prev(p), next(n) { } 49 44 ListNode(ValueImp *val, ListNode *p, ListNode *n) 50 : member(val), prev(p), next(n) { };45 : member(val), prev(p), next(n) { } 51 46 ValueImp *member; 52 47 ListNode *prev, *next; 53 48 }; 54 49 55 classListHookNode : public ListNode {56 friend class List;57 58 ListHookNode() : ListNode(Value(), NULL, NULL), refcount(1) { prev = this; next = this; }59 int refcount;50 struct ListHookNode : public ListNode { 51 ListHookNode(bool needsMarking) : ListNode(Value(), this, this), 52 listRefCount(1), nodesRefCount(needsMarking ? 0 : 1) { } 53 int listRefCount; 54 int nodesRefCount; 60 55 }; 61 }62 63 56 64 57 // ------------------------------ ListIterator --------------------------------- … … 102 95 // ------------------------------ List ----------------------------------------- 103 96 104 List::List(bool needsMarking) 105 : hook(new ListHookNode()), 106 m_needsMarking(needsMarking) 107 { 108 if (!m_needsMarking) { 97 List::List(bool needsMarking) : hook(new ListHookNode(needsMarking)), m_needsMarking(needsMarking) 98 { 99 } 100 101 List::List(const List& l) : hook(l.hook), m_needsMarking(false) 102 { 103 ++hook->listRefCount; 104 if (hook->nodesRefCount++ == 0) 109 105 refAll(); 110 }111 }112 113 114 List::List(const List& l)115 : hook(l.hook),116 m_needsMarking(false)117 {118 hook->refcount++;119 if (!m_needsMarking) {120 refAll();121 }122 106 } 123 107 124 108 List& List::operator=(const List& l) 125 109 { 126 List tmp(l); 127 128 tmp.swap(*this); 129 110 List(l).swap(*this); 130 111 return *this; 131 112 } 132 113 133 114 List::~List() 134 115 { 135 if (!m_needsMarking) {136 derefAll();137 }116 if (!m_needsMarking) 117 if (--hook->nodesRefCount == 0) 118 derefAll(); 138 119 139 hook->refcount--;140 if (hook->refcount == 0) {120 if (--hook->listRefCount == 0) { 121 assert(hook->nodesRefCount == 0); 141 122 clearInternal(); 142 123 delete hook; … … 157 138 { 158 139 ListNode *n = new ListNode(val, hook->prev, hook); 159 if ( !m_needsMarking) {140 if (hook->nodesRefCount) 160 141 n->member->ref(); 161 }162 142 hook->prev->next = n; 163 143 hook->prev = n; … … 167 147 { 168 148 ListNode *n = new ListNode(val, hook->prev, hook); 169 if ( !m_needsMarking) {149 if (hook->nodesRefCount) 170 150 val->ref(); 171 }172 151 hook->prev->next = n; 173 152 hook->prev = n; … … 177 156 { 178 157 ListNode *n = new ListNode(val, hook, hook->next); 179 if ( !m_needsMarking) {158 if (hook->nodesRefCount) 180 159 n->member->ref(); 181 }182 160 hook->next->prev = n; 183 161 hook->next = n; … … 187 165 { 188 166 ListNode *n = new ListNode(val, hook, hook->next); 189 if ( !m_needsMarking) {167 if (hook->nodesRefCount) 190 168 val->ref(); 191 }192 169 hook->next->prev = n; 193 170 hook->next = n; … … 218 195 if (val.isNull()) 219 196 return; 220 ListNode *n = hook->next; 221 while (n != hook) { 197 for (ListNode *n = hook->next; n != hook; n = n->next) 222 198 if (n->member == val.imp()) { 223 199 erase(n); 224 200 return; 225 201 } 226 n = n->next;227 }228 202 } 229 203 230 204 void List::clear() 231 205 { 232 if ( !m_needsMarking) {206 if (hook->nodesRefCount) 233 207 derefAll(); 234 }235 208 clearInternal(); 236 209 } … … 267 240 bool List::isEmpty() const 268 241 { 269 return (hook->prev == hook);242 return hook->prev == hook; 270 243 } 271 244 … … 273 246 { 274 247 int s = 0; 275 ListNode *node = hook; 276 while ((node = node->next) != hook) 248 for (ListNode *n = hook->next; n != hook; n = n->next) 277 249 s++; 278 279 250 return s; 280 251 } … … 307 278 { 308 279 if (n != hook) { 309 if ( !m_needsMarking) {280 if (hook->nodesRefCount) 310 281 n->member->deref(); 311 }312 282 n->next->prev = n->prev; 313 283 n->prev->next = n->next; … … 318 288 void List::refAll() 319 289 { 320 ListNode *n = hook->next; 321 322 while (n != hook) { 290 for (ListNode *n = hook->next; n != hook; n = n->next) 323 291 n->member->ref(); 324 n = n->next;325 }326 292 } 327 293 328 294 void List::derefAll() 329 295 { 330 ListNode *n = hook->next; 331 332 while (n != hook) { 296 for (ListNode *n = hook->next; n != hook; n = n->next) 333 297 n->member->deref(); 334 n = n->next;335 }336 298 } 337 299 338 300 void List::swap(List &other) 339 301 { 340 if (m_needsMarking && !other.m_needsMarking) { 341 refAll(); 342 other.derefAll(); 343 } else if (!m_needsMarking && other.m_needsMarking) { 344 other.refAll(); 345 derefAll(); 346 } 302 if (!m_needsMarking) 303 if (other.hook->nodesRefCount++ == 0) 304 other.refAll(); 305 if (!other.m_needsMarking) 306 if (hook->nodesRefCount++ == 0) 307 refAll(); 308 309 if (!m_needsMarking) 310 if (--hook->nodesRefCount == 0) 311 derefAll(); 312 if (!other.m_needsMarking) 313 if (--other.hook->nodesRefCount == 0) 314 other.derefAll(); 347 315 348 316 ListHookNode *tmp = hook; … … 353 321 void List::replaceFirst(ValueImp *v) 354 322 { 355 356 if (!m_needsMarking) {357 358 359 360 323 ListNode *n = hook->next; 324 if (hook->nodesRefCount) { 325 v->ref(); 326 n->member->deref(); 327 } 328 n->member = v; 361 329 } 362 330 363 331 void List::replaceLast(ValueImp *v) 364 332 { 365 ListNode *n = hook->prev; 366 if (!m_needsMarking) { 367 v->ref(); 368 n->member->deref(); 369 } 370 n->member = v; 371 } 333 ListNode *n = hook->prev; 334 if (hook->nodesRefCount) { 335 v->ref(); 336 n->member->deref(); 337 } 338 n->member = v; 339 } 340 341 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.