Ignore:
Timestamp:
Sep 4, 2007, 10:01:03 PM (18 years ago)
Author:
mjs
Message:

Reviewed by Darin.


  • Added Vector::appendRange(), which appends to a vector based on a given start and end iterator
  • Added keys() and values() functions to HashMap iterators, which give keys-only and values-only iterators


Together, these allow easy copying of a set, or the keys or values of a map, into a Vector. Examples:


HashMap<int, int> map;
HashSet<int> set;
Vector<int> vec;
...
vec.appendRange(set.begin(), set.end());
vec.appendRange(map.begin().keys(), map.end().keys());
vec.appendRange(map.begin().values(), map.end().values());

This also allows for a slightly nicer syntax when iterating a map. Instead of saying
(*it)->first, you can say *it.values(). Similarly for keys. Example:


HashMap<int, int>::const_iterator end = map.end();
for (HashMap<int, int>::const_iterator it = map.begin(); it != end; ++it)
printf(" [%d => %d]", *it.keys(), *it.values());

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • wtf/HashIterators.h: Added. (WTF::): (WTF::HashTableConstKeysIterator::HashTableConstKeysIterator): (WTF::HashTableConstKeysIterator::get): (WTF::HashTableConstKeysIterator::operator*): (WTF::HashTableConstKeysIterator::operator->): (WTF::HashTableConstKeysIterator::operator++): (WTF::HashTableConstValuesIterator::HashTableConstValuesIterator): (WTF::HashTableConstValuesIterator::get): (WTF::HashTableConstValuesIterator::operator*): (WTF::HashTableConstValuesIterator::operator->): (WTF::HashTableConstValuesIterator::operator++): (WTF::HashTableKeysIterator::HashTableKeysIterator): (WTF::HashTableKeysIterator::get): (WTF::HashTableKeysIterator::operator*): (WTF::HashTableKeysIterator::operator->): (WTF::HashTableKeysIterator::operator++): (WTF::HashTableKeysIterator::operator HashTableConstKeysIterator<HashTableType, KeyType, MappedType>): (WTF::HashTableValuesIterator::HashTableValuesIterator): (WTF::HashTableValuesIterator::get): (WTF::HashTableValuesIterator::operator*): (WTF::HashTableValuesIterator::operator->): (WTF::HashTableValuesIterator::operator++): (WTF::HashTableValuesIterator::operator HashTableConstValuesIterator<HashTableType, KeyType, MappedType>): (WTF::operator==): (WTF::operator!=):
  • wtf/HashTable.h:
  • wtf/Vector.h: (WTF::::appendRange):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/collector.cpp

    r25296 r25365  
    3030#include <stdlib.h>
    3131#include <wtf/FastMalloc.h>
    32 #include <wtf/FastMallocInternal.h>
    3332#include <wtf/HashCountedSet.h>
    3433#include <wtf/UnusedParam.h>
     
    401400
    402401  if (!pthread_getspecific(registeredThreadKey)) {
    403     if (!onMainThread())
    404         WTF::fastMallocSetIsMultiThreaded();
    405 #if PLATFORM(DARWIN)
    406     else
    407         CollectorHeapIntrospector::init(&heap);
     402#if PLATFORM(DARWIN)
     403      if (onMainThread())
     404          CollectorHeapIntrospector::init(&heap);
    408405#endif
    409406
Note: See TracChangeset for help on using the changeset viewer.