PropertyNameArray.cpp 1.68 KB
Newer Older
mjs's avatar
mjs committed
1
/*
darin@apple.com's avatar
darin@apple.com committed
2
 *  Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
mjs's avatar
mjs committed
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
ddkilzer's avatar
ddkilzer committed
16
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
mjs's avatar
mjs committed
17 18 19 20 21 22 23
 *  Boston, MA 02110-1301, USA.
 *
 */

#include "config.h"
#include "PropertyNameArray.h"

24
#include "JSObject.h"
25

26 27 28
#include "Structure.h"
#include "StructureChain.h"

29
namespace JSC {
mjs's avatar
mjs committed
30

darin@apple.com's avatar
darin@apple.com committed
31
static const size_t setThreshold = 20;
mjs's avatar
mjs committed
32

33
void PropertyNameArray::add(StringImpl* identifier)
andersca@apple.com's avatar
andersca@apple.com committed
34
{
35
    ASSERT(!identifier || identifier == StringImpl::empty() || identifier->isIdentifier());
andersca@apple.com's avatar
andersca@apple.com committed
36

37
    size_t size = m_data->propertyNameVector().size();
darin@apple.com's avatar
darin@apple.com committed
38 39
    if (size < setThreshold) {
        for (size_t i = 0; i < size; ++i) {
40
            if (identifier == m_data->propertyNameVector()[i].impl())
darin@apple.com's avatar
darin@apple.com committed
41 42 43 44 45
                return;
        }
    } else {
        if (m_set.isEmpty()) {
            for (size_t i = 0; i < size; ++i)
46
                m_set.add(m_data->propertyNameVector()[i].impl());
darin@apple.com's avatar
darin@apple.com committed
47
        }
48
        if (!m_set.add(identifier).isNewEntry)
darin@apple.com's avatar
darin@apple.com committed
49 50
            return;
    }
andersca@apple.com's avatar
andersca@apple.com committed
51

52
    addKnownUnique(identifier);
darin@apple.com's avatar
darin@apple.com committed
53
}
mjs's avatar
mjs committed
54

55
} // namespace JSC