OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/dom/DOMStringList.h" | 27 #include "core/dom/DOMStringList.h" |
| 28 #include "core/dom/ExecutionContext.h" |
| 29 #include "core/frame/UseCounter.h" |
28 #include <algorithm> | 30 #include <algorithm> |
29 | 31 |
30 namespace blink { | 32 namespace blink { |
31 | 33 |
32 String DOMStringList::item(unsigned index) const | 34 String DOMStringList::anonymousIndexedGetter(unsigned index) const |
33 { | 35 { |
34 if (index >= m_strings.size()) | 36 if (index >= m_strings.size()) |
35 return String(); | 37 return String(); |
36 return m_strings[index]; | 38 return m_strings[index]; |
37 } | 39 } |
38 | 40 |
39 bool DOMStringList::contains(const String& string) const | 41 |
| 42 String DOMStringList::item(ExecutionContext* context, unsigned index) const |
40 { | 43 { |
| 44 switch (m_source) { |
| 45 case DOMStringList::IndexedDB: |
| 46 UseCounter::count(context, UseCounter::DOMStringList_Item_AttributeGette
r_IndexedDB); |
| 47 break; |
| 48 case DOMStringList::Location: |
| 49 UseCounter::count(context, UseCounter::DOMStringList_Item_AttributeGette
r_Location); |
| 50 break; |
| 51 default: |
| 52 ASSERT_NOT_REACHED(); |
| 53 } |
| 54 |
| 55 return anonymousIndexedGetter(index); |
| 56 } |
| 57 |
| 58 bool DOMStringList::contains(ExecutionContext* context, const String& string) co
nst |
| 59 { |
| 60 switch (m_source) { |
| 61 case DOMStringList::IndexedDB: |
| 62 UseCounter::count(context, UseCounter::DOMStringList_Contains_Method_Ind
exedDB); |
| 63 break; |
| 64 case DOMStringList::Location: |
| 65 UseCounter::count(context, UseCounter::DOMStringList_Contains_Method_Loc
ation); |
| 66 break; |
| 67 default: |
| 68 ASSERT_NOT_REACHED(); |
| 69 } |
| 70 |
41 // FIXME: Currently, all consumers of DOMStringList store fairly small lists
and thus an O(n) | 71 // FIXME: Currently, all consumers of DOMStringList store fairly small lists
and thus an O(n) |
42 // algorithm is OK. But this may need to be optimized if larger amou
nts of data are | 72 // algorithm is OK. But this may need to be optimized if larger amou
nts of data are |
43 // stored in m_strings. | 73 // stored in m_strings. |
44 size_t count = m_strings.size(); | 74 size_t count = m_strings.size(); |
45 for (size_t i = 0; i < count; ++i) { | 75 for (size_t i = 0; i < count; ++i) { |
46 if (m_strings[i] == string) | 76 if (m_strings[i] == string) |
47 return true; | 77 return true; |
48 } | 78 } |
49 return false; | 79 return false; |
50 } | 80 } |
51 | 81 |
52 void DOMStringList::sort() | 82 void DOMStringList::sort() |
53 { | 83 { |
54 std::sort(m_strings.begin(), m_strings.end(), WTF::codePointCompareLessThan)
; | 84 std::sort(m_strings.begin(), m_strings.end(), WTF::codePointCompareLessThan)
; |
55 } | 85 } |
56 | 86 |
57 } // namespace blink | 87 } // namespace blink |
OLD | NEW |