1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 2005 Apple Computer, Inc
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Library General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Library General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Library General Public License
|
---|
17 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
18 | * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
---|
19 | * Boston, MA 02110-1301, USA.
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "config.h"
|
---|
24 | #include "IdentifierSequencedSet.h"
|
---|
25 |
|
---|
26 | namespace KJS {
|
---|
27 |
|
---|
28 | IdentifierSequencedSet::IdentifierSequencedSet()
|
---|
29 | : m_vector(0),
|
---|
30 | m_vectorLength(0),
|
---|
31 | m_vectorCapacity(0)
|
---|
32 | {
|
---|
33 | }
|
---|
34 |
|
---|
35 | void IdentifierSequencedSet::deallocateVector()
|
---|
36 | {
|
---|
37 | for (int i = 0; i < m_vectorLength; ++i) {
|
---|
38 | (m_vector + i)->~Identifier();
|
---|
39 | }
|
---|
40 | fastFree(m_vector);
|
---|
41 | }
|
---|
42 |
|
---|
43 | IdentifierSequencedSet::~IdentifierSequencedSet()
|
---|
44 | {
|
---|
45 | deallocateVector();
|
---|
46 | }
|
---|
47 |
|
---|
48 | void IdentifierSequencedSet::insert(const Identifier& ident)
|
---|
49 | {
|
---|
50 | if (!m_set.insert(ident.ustring().impl()).second)
|
---|
51 | return;
|
---|
52 |
|
---|
53 | if (m_vectorLength == m_vectorCapacity) {
|
---|
54 | m_vectorCapacity = m_vectorCapacity == 0 ? 16 : m_vectorCapacity * 11 / 10;
|
---|
55 | Identifier *newVector = reinterpret_cast<Identifier *>(fastMalloc(m_vectorCapacity * sizeof(Identifier)));
|
---|
56 | for (int i = 0; i < m_vectorLength; ++i) {
|
---|
57 | new (newVector + i) Identifier(m_vector[i]);
|
---|
58 | }
|
---|
59 | deallocateVector();
|
---|
60 | m_vector = newVector;
|
---|
61 | }
|
---|
62 | new (m_vector + m_vectorLength) Identifier(ident);
|
---|
63 | ++m_vectorLength;
|
---|
64 | }
|
---|
65 |
|
---|
66 | } // namespace KJS
|
---|
67 |
|
---|