2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
22 #include "CollectionCache.h"
26 CollectionCache::CollectionCache()
32 inline void CollectionCache::copyCacheMap(NodeCacheMap
& dest
, const NodeCacheMap
& src
)
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
));
40 CollectionCache::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
)
49 copyCacheMap(idCache
, other
.idCache
);
50 copyCacheMap(nameCache
, other
.nameCache
);
53 void CollectionCache::swap(CollectionCache
& other
)
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
);
61 idCache
.swap(other
.idCache
);
62 nameCache
.swap(other
.nameCache
);
64 std::swap(hasLength
, other
.hasLength
);
65 std::swap(hasNameCache
, other
.hasNameCache
);
68 CollectionCache::~CollectionCache()
70 deleteAllValues(idCache
);
71 deleteAllValues(nameCache
);
74 void CollectionCache::reset()
80 elementsArrayPosition
= 0;
81 deleteAllValues(idCache
);
83 deleteAllValues(nameCache
);
88 } // namespace WebCore