1/* 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21#include "config.h" 22#include "CollectionCache.h" 23 24namespace WebCore { 25 26CollectionCache::CollectionCache() 27 : version(0) 28{ 29 reset(); 30} 31 32inline void CollectionCache::copyCacheMap(NodeCacheMap& dest, const NodeCacheMap& src) 33{ 34 ASSERT(dest.isEmpty()); 35 NodeCacheMap::const_iterator end = src.end(); 36 for (NodeCacheMap::const_iterator it = src.begin(); it != end; ++it) 37 dest.add(it->first, new Vector<Element*>(*it->second)); 38} 39 40CollectionCache::CollectionCache(const CollectionCache& other) 41 : version(other.version) 42 , current(other.current) 43 , position(other.position) 44 , length(other.length) 45 , elementsArrayPosition(other.elementsArrayPosition) 46 , hasLength(other.hasLength) 47 , hasNameCache(other.hasNameCache) 48{ 49 copyCacheMap(idCache, other.idCache); 50 copyCacheMap(nameCache, other.nameCache); 51} 52 53void CollectionCache::swap(CollectionCache& other) 54{ 55 std::swap(version, other.version); 56 std::swap(current, other.current); 57 std::swap(position, other.position); 58 std::swap(length, other.length); 59 std::swap(elementsArrayPosition, other.elementsArrayPosition); 60 61 idCache.swap(other.idCache); 62 nameCache.swap(other.nameCache); 63 64 std::swap(hasLength, other.hasLength); 65 std::swap(hasNameCache, other.hasNameCache); 66} 67 68CollectionCache::~CollectionCache() 69{ 70 deleteAllValues(idCache); 71 deleteAllValues(nameCache); 72} 73 74void CollectionCache::reset() 75{ 76 current = 0; 77 position = 0; 78 length = 0; 79 hasLength = false; 80 elementsArrayPosition = 0; 81 deleteAllValues(idCache); 82 idCache.clear(); 83 deleteAllValues(nameCache); 84 nameCache.clear(); 85 hasNameCache = false; 86} 87 88#if !ASSERT_DISABLED 89void CollectionCache::checkConsistency() 90{ 91 idCache.checkConsistency(); 92 nameCache.checkConsistency(); 93} 94#endif 95 96} // namespace WebCore 97