source: webkit/trunk/JavaScriptCore/runtime/RegExpKey.h@ 65289

Last change on this file since 65289 was 65286, checked in by [email protected], 15 years ago

Change UString constructors to match those in WTF::String.
This changes behaviour of UString((char*)0) to create null
strings, akin to UString() rather than UString::empty().
(This matches String). Remove unused constructors from
UString, and add null-terminated UTF-16 constructor, to
match String. Move String's constructor into the .cpp to
match UString.

Reviewed by Sam Weinig

(JSC::DebuggerCallFrame::calculatedFunctionName):

  • runtime/RegExpKey.h:

(JSC::RegExpKey::RegExpKey):

  • runtime/SmallStrings.cpp:

(JSC::SmallStrings::createSingleCharacterString):

  • runtime/UString.cpp:

(JSC::UString::UString):

  • runtime/UString.h:

(JSC::UString::UString):
(JSC::UString::swap):
(JSC::UString::adopt):
(JSC::UString::operator[]):

  • wtf/text/WTFString.h:

(WTF::String::String):
(WTF::String::adopt):
(WTF::String::operator[]):

File size: 3.6 KB
Line 
1/*
2 * Copyright (C) 2010 University of Szeged
3 * Copyright (C) 2010 Renata Hodovan ([email protected])
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "UString.h"
29
30#ifndef RegExpKey_h
31#define RegExpKey_h
32
33namespace JSC {
34
35struct RegExpKey {
36 int flagsValue;
37 RefPtr<StringImpl> pattern;
38
39 RegExpKey()
40 : flagsValue(0)
41 {
42 }
43
44 RegExpKey(int flags)
45 : flagsValue(flags)
46 {
47 }
48
49 RegExpKey(int flags, const UString& pattern)
50 : flagsValue(flags)
51 , pattern(pattern.impl())
52 {
53 }
54
55 RegExpKey(int flags, const PassRefPtr<StringImpl> pattern)
56 : flagsValue(flags)
57 , pattern(pattern)
58 {
59 }
60
61 RegExpKey(int flags, const RefPtr<StringImpl>& pattern)
62 : flagsValue(flags)
63 , pattern(pattern)
64 {
65 }
66
67 RegExpKey(const UString& flags, const UString& pattern)
68 : pattern(pattern.impl())
69 {
70 flagsValue = getFlagsValue(flags);
71 }
72
73 int getFlagsValue(const UString flags)
74 {
75 flagsValue = 0;
76 if (flags.find('g') != UString::NotFound)
77 flagsValue += 4;
78 if (flags.find('i') != UString::NotFound)
79 flagsValue += 2;
80 if (flags.find('m') != UString::NotFound)
81 flagsValue += 1;
82 return flagsValue;
83 }
84};
85
86inline bool operator==(const RegExpKey& a, const RegExpKey& b)
87{
88 if (a.flagsValue != b.flagsValue)
89 return false;
90 if (!a.pattern)
91 return !b.pattern;
92 if (!b.pattern)
93 return false;
94 return equal(a.pattern.get(), b.pattern.get());
95}
96
97} // namespace JSC
98
99namespace WTF {
100template<typename T> struct DefaultHash;
101template<typename T> struct RegExpHash;
102
103template<> struct RegExpHash<JSC::RegExpKey> {
104 static unsigned hash(const JSC::RegExpKey& key) { return key.pattern->hash(); }
105 static bool equal(const JSC::RegExpKey& a, const JSC::RegExpKey& b) { return a == b; }
106 static const bool safeToCompareToEmptyOrDeleted = false;
107};
108
109template<> struct DefaultHash<JSC::RegExpKey> {
110 typedef RegExpHash<JSC::RegExpKey> Hash;
111};
112
113template<> struct HashTraits<JSC::RegExpKey> : GenericHashTraits<JSC::RegExpKey> {
114 static void constructDeletedValue(JSC::RegExpKey& slot) { slot.flagsValue = -1; }
115 static bool isDeletedValue(const JSC::RegExpKey& value) { return value.flagsValue == -1; }
116};
117} // namespace WTF
118
119#endif // RegExpKey_h
Note: See TracBrowser for help on using the repository browser.