Changeset 11561 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- Dec 13, 2005, 3:06:10 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r11527 r11561 25 25 #include <kxmlcore/FastMalloc.h> 26 26 #include <kxmlcore/FastMallocInternal.h> 27 #include <kxmlcore/HashCountedSet.h> 27 28 #include "internal.h" 28 29 #include "list.h" … … 379 380 } 380 381 382 typedef HashCountedSet<JSCell *, PointerHash<JSCell *> > ProtectCounts; 383 384 static ProtectCounts& protectedValues() 385 { 386 static ProtectCounts pv; 387 return pv; 388 } 389 390 void Collector::protect(JSValue *k) 391 { 392 assert(k); 393 assert(JSLock::lockCount() > 0); 394 395 if (SimpleNumber::is(k)) 396 return; 397 398 protectedValues().insert(k->downcast()); 399 } 400 401 void Collector::unprotect(JSValue *k) 402 { 403 assert(k); 404 assert(JSLock::lockCount() > 0); 405 406 if (SimpleNumber::is(k)) 407 return; 408 409 protectedValues().remove(k->downcast()); 410 } 411 381 412 void Collector::markProtectedObjects() 382 413 { 383 typedef ProtectedValues::KeyValue Entry; 384 Entry *table = ProtectedValues::_table; 385 Entry *end = table + ProtectedValues::_tableSize; 386 for (Entry *entry = table; entry != end; ++entry) { 387 JSCell *val = entry->key; 388 if (val && !val->marked()) { 414 ProtectCounts& pv = protectedValues(); 415 ProtectCounts::iterator end = pv.end(); 416 for (ProtectCounts::iterator it = pv.begin(); it != end; ++it) { 417 JSCell *val = it->first; 418 if (!val->marked()) 389 419 val->mark(); 390 }391 420 } 392 421 } … … 559 588 size_t Collector::numReferencedObjects() 560 589 { 561 size_t count = 0; 562 563 size_t size = ProtectedValues::_tableSize; 564 ProtectedValues::KeyValue *table = ProtectedValues::_table; 565 for (size_t i = 0; i < size; i++) { 566 JSCell *val = table[i].key; 567 if (val) { 568 ++count; 569 } 570 } 571 572 return count; 590 return protectedValues().size(); 573 591 } 574 592 … … 607 625 const void *Collector::rootObjectClasses() 608 626 { 627 // FIXME: this should be a HashSet (or maybe even CountedHashSet) 609 628 CFMutableSetRef classes = CFSetCreateMutable(NULL, 0, &kCFTypeSetCallBacks); 610 629 611 int size = ProtectedValues::_tableSize; 612 ProtectedValues::KeyValue *table = ProtectedValues::_table; 613 for (int i = 0; i < size; i++) { 614 JSCell *val = table[i].key; 615 if (val) { 616 CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII); 617 CFSetAddValue(classes, name); 618 CFRelease(name); 619 } 620 } 621 630 ProtectCounts& pv = protectedValues(); 631 ProtectCounts::iterator end = pv.end(); 632 for (ProtectCounts::iterator it = pv.begin(); it != end; ++it) { 633 JSCell *val = it->first; 634 CFStringRef name = CFStringCreateWithCString(NULL, className(val), kCFStringEncodingASCII); 635 CFSetAddValue(classes, name); 636 CFRelease(name); 637 } 638 622 639 return classes; 623 640 }
Note:
See TracChangeset
for help on using the changeset viewer.