source: webkit/trunk/JavaScriptCore/runtime/UString.h@ 58990

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

JavaScriptCore: Bug 37906 - Remove JSC::UStringImpl; unify with StringImpl.

Reviewed by Oliver Hunt, Darin Adler.

JSC::UStringImpl and WebCore::StringImpl (soon to be renamed to
WTF::StringImpl) are almost identical. Remove duplication of code by unifying
the two, move missing features from UStringImpl into StringImpl & delete the
class UStringImpl.

  • API/JSClassRef.cpp:
  • API/JSContextRef.cpp:
  • GNUmakefile.am:
  • JavaScriptCore.exp:
  • JavaScriptCore.pro:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecode/EvalCodeCache.h:
  • bytecode/JumpTable.cpp:
  • profiler/ProfileNode.cpp:
  • runtime/Identifier.cpp:

(JSC::Identifier::add):

  • runtime/Identifier.h:

(JSC::Identifier::equal):

  • runtime/UString.cpp:
  • runtime/UString.h:

(WTF::):

  • runtime/UStringImpl.cpp: Removed.
  • runtime/UStringImpl.h:
  • wtf/text/StringHash.h:

(WebCore::StringHash::equal):
(WebCore::CaseFoldingHash::equal):

  • wtf/text/StringImpl.cpp:

(WebCore::StringImpl::~StringImpl):
(WebCore::StringImpl::empty):
(WebCore::StringImpl::sharedBuffer):
(WebCore::equal):

  • wtf/text/StringImpl.h:

(WebCore::StringImpl::StringImpl):
(WebCore::StringImpl::create):
(WebCore::StringImpl::tryCreateUninitialized):
(WebCore::StringImpl::cost):
(WebCore::StringImpl::isIdentifier):
(WebCore::StringImpl::setIsIdentifier):
(WebCore::StringImpl::computeHash):
(WebCore::StringImpl::copyChars):
(WebCore::StringImpl::):

JavaScriptGlue: Bug 37906 - Remove JSC::UStringImpl; unify with StringImpl.
Add forwarding header.

Reviewed by Oliver Hunt, Darin Adler.

  • ForwardingHeaders/wtf/ASCIICType.h: Added.
  • ForwardingHeaders/wtf/text/StringImpl.h: Added.

WebCore: Bug 37906 - Remove JSC::UStringImpl; unify with StringImpl.
Add include for StringHash.h.

Reviewed by Oliver Hunt, Darin Adler.

  • WebCore.xcodeproj/project.pbxproj:
  • bridge/c/c_class.cpp:
  • Property svn:eol-style set to native
File size: 23.2 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved.
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 Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef UString_h
24#define UString_h
25
26#include "Collector.h"
27#include "UStringImpl.h"
28#include <stdint.h>
29#include <string.h>
30#include <wtf/Assertions.h>
31#include <wtf/CrossThreadRefCounted.h>
32#include <wtf/OwnFastMallocPtr.h>
33#include <wtf/PassRefPtr.h>
34#include <wtf/RefPtr.h>
35#include <wtf/Vector.h>
36#include <wtf/text/CString.h>
37#include <wtf/unicode/Unicode.h>
38
39namespace JSC {
40
41 using WTF::PlacementNewAdoptType;
42 using WTF::PlacementNewAdopt;
43
44 class UString {
45 friend class JIT;
46
47 public:
48 typedef UStringImpl Rep;
49
50 public:
51 UString() {}
52 UString(const char*); // Constructor for null-terminated string.
53 UString(const char*, unsigned length);
54 UString(const UChar*, unsigned length);
55 UString(const Vector<UChar>& buffer);
56
57 UString(const UString& s)
58 : m_rep(s.m_rep)
59 {
60 }
61
62 // Special constructor for cases where we overwrite an object in place.
63 UString(PlacementNewAdoptType)
64 : m_rep(PlacementNewAdopt)
65 {
66 }
67
68 template<size_t inlineCapacity>
69 static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector)
70 {
71 return Rep::adopt(vector);
72 }
73
74 static UString from(int);
75 static UString from(long long);
76 static UString from(unsigned);
77 static UString from(long);
78 static UString from(double);
79
80 // NOTE: This method should only be used for *debugging* purposes as it
81 // is neither Unicode safe nor free from side effects nor thread-safe.
82 char* ascii() const;
83
84 /**
85 * Convert the string to UTF-8, assuming it is UTF-16 encoded.
86 * In non-strict mode, this function is tolerant of badly formed UTF-16, it
87 * can create UTF-8 strings that are invalid because they have characters in
88 * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is
89 * guaranteed to be otherwise valid.
90 * In strict mode, error is returned as null CString.
91 */
92 CString UTF8String(bool strict = false) const;
93
94 const UChar* data() const
95 {
96 if (!m_rep)
97 return 0;
98 return m_rep->characters();
99 }
100
101 unsigned size() const
102 {
103 if (!m_rep)
104 return 0;
105 return m_rep->length();
106 }
107
108 bool isNull() const { return !m_rep; }
109 bool isEmpty() const { return !m_rep || !m_rep->length(); }
110
111 bool is8Bit() const;
112
113 UChar operator[](unsigned pos) const;
114
115 double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
116 double toDouble(bool tolerateTrailingJunk) const;
117 double toDouble() const;
118
119 uint32_t toUInt32(bool* ok = 0) const;
120 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const;
121 uint32_t toStrictUInt32(bool* ok = 0) const;
122
123 unsigned toArrayIndex(bool* ok = 0) const;
124
125 static const unsigned NotFound = 0xFFFFFFFFu;
126 unsigned find(const UString& f, unsigned pos = 0) const;
127 unsigned find(UChar, unsigned pos = 0) const;
128 unsigned rfind(const UString& f, unsigned pos) const;
129 unsigned rfind(UChar, unsigned pos) const;
130
131 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const;
132
133 static const UString& null() { return *s_nullUString; }
134
135 Rep* rep() const { return m_rep.get(); }
136
137 UString(PassRefPtr<Rep> r)
138 : m_rep(r)
139 {
140 }
141
142 size_t cost() const
143 {
144 if (!m_rep)
145 return 0;
146 return m_rep->cost();
147 }
148
149 private:
150 RefPtr<Rep> m_rep;
151
152 static UString* s_nullUString;
153
154 friend void initializeUString();
155 friend bool operator==(const UString&, const UString&);
156 };
157
158 ALWAYS_INLINE bool operator==(const UString& s1, const UString& s2)
159 {
160 unsigned size = s1.size();
161 switch (size) {
162 case 0:
163 return !s2.size();
164 case 1:
165 return s2.size() == 1 && s1.data()[0] == s2.data()[0];
166 case 2: {
167 if (s2.size() != 2)
168 return false;
169 const UChar* d1 = s1.data();
170 const UChar* d2 = s2.data();
171 return (d1[0] == d2[0]) & (d1[1] == d2[1]);
172 }
173 default:
174 return s2.size() == size && memcmp(s1.data(), s2.data(), size * sizeof(UChar)) == 0;
175 }
176 }
177
178
179 inline bool operator!=(const UString& s1, const UString& s2)
180 {
181 return !JSC::operator==(s1, s2);
182 }
183
184 bool operator<(const UString& s1, const UString& s2);
185 bool operator>(const UString& s1, const UString& s2);
186
187 bool operator==(const UString& s1, const char* s2);
188
189 inline bool operator!=(const UString& s1, const char* s2)
190 {
191 return !JSC::operator==(s1, s2);
192 }
193
194 inline bool operator==(const char *s1, const UString& s2)
195 {
196 return operator==(s2, s1);
197 }
198
199 inline bool operator!=(const char *s1, const UString& s2)
200 {
201 return !JSC::operator==(s1, s2);
202 }
203
204 int compare(const UString&, const UString&);
205
206 // Rule from ECMA 15.2 about what an array index is.
207 // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
208 inline unsigned UString::toArrayIndex(bool* ok) const
209 {
210 unsigned i = toStrictUInt32(ok);
211 if (ok && i >= 0xFFFFFFFFU)
212 *ok = false;
213 return i;
214 }
215
216 // We'd rather not do shared substring append for small strings, since
217 // this runs too much risk of a tiny initial string holding down a
218 // huge buffer.
219 static const unsigned minShareSize = Heap::minExtraCost / sizeof(UChar);
220
221 struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > {
222 static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->existingHash(); }
223 static unsigned hash(JSC::UString::Rep* key) { return key->existingHash(); }
224 };
225
226 void initializeUString();
227
228 template<typename StringType>
229 class StringTypeAdapter {
230 };
231
232 template<>
233 class StringTypeAdapter<char*> {
234 public:
235 StringTypeAdapter<char*>(char* buffer)
236 : m_buffer((unsigned char*)buffer)
237 , m_length(strlen(buffer))
238 {
239 }
240
241 unsigned length() { return m_length; }
242
243 void writeTo(UChar* destination)
244 {
245 for (unsigned i = 0; i < m_length; ++i)
246 destination[i] = m_buffer[i];
247 }
248
249 private:
250 const unsigned char* m_buffer;
251 unsigned m_length;
252 };
253
254 template<>
255 class StringTypeAdapter<const char*> {
256 public:
257 StringTypeAdapter<const char*>(const char* buffer)
258 : m_buffer((unsigned char*)buffer)
259 , m_length(strlen(buffer))
260 {
261 }
262
263 unsigned length() { return m_length; }
264
265 void writeTo(UChar* destination)
266 {
267 for (unsigned i = 0; i < m_length; ++i)
268 destination[i] = m_buffer[i];
269 }
270
271 private:
272 const unsigned char* m_buffer;
273 unsigned m_length;
274 };
275
276 template<>
277 class StringTypeAdapter<UString> {
278 public:
279 StringTypeAdapter<UString>(UString& string)
280 : m_data(string.data())
281 , m_length(string.size())
282 {
283 }
284
285 unsigned length() { return m_length; }
286
287 void writeTo(UChar* destination)
288 {
289 for (unsigned i = 0; i < m_length; ++i)
290 destination[i] = m_data[i];
291 }
292
293 private:
294 const UChar* m_data;
295 unsigned m_length;
296 };
297
298 inline void sumWithOverflow(unsigned& total, unsigned addend, bool& overflow)
299 {
300 unsigned oldTotal = total;
301 total = oldTotal + addend;
302 if (total < oldTotal)
303 overflow = true;
304 }
305
306 template<typename StringType1, typename StringType2>
307 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2)
308 {
309 StringTypeAdapter<StringType1> adapter1(string1);
310 StringTypeAdapter<StringType2> adapter2(string2);
311
312 UChar* buffer;
313 bool overflow = false;
314 unsigned length = adapter1.length();
315 sumWithOverflow(length, adapter2.length(), overflow);
316 if (overflow)
317 return 0;
318 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
319 if (!resultImpl)
320 return 0;
321
322 UChar* result = buffer;
323 adapter1.writeTo(result);
324 result += adapter1.length();
325 adapter2.writeTo(result);
326
327 return resultImpl;
328 }
329
330 template<typename StringType1, typename StringType2, typename StringType3>
331 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3)
332 {
333 StringTypeAdapter<StringType1> adapter1(string1);
334 StringTypeAdapter<StringType2> adapter2(string2);
335 StringTypeAdapter<StringType3> adapter3(string3);
336
337 UChar* buffer;
338 bool overflow = false;
339 unsigned length = adapter1.length();
340 sumWithOverflow(length, adapter2.length(), overflow);
341 sumWithOverflow(length, adapter3.length(), overflow);
342 if (overflow)
343 return 0;
344 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
345 if (!resultImpl)
346 return 0;
347
348 UChar* result = buffer;
349 adapter1.writeTo(result);
350 result += adapter1.length();
351 adapter2.writeTo(result);
352 result += adapter2.length();
353 adapter3.writeTo(result);
354
355 return resultImpl;
356 }
357
358 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4>
359 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4)
360 {
361 StringTypeAdapter<StringType1> adapter1(string1);
362 StringTypeAdapter<StringType2> adapter2(string2);
363 StringTypeAdapter<StringType3> adapter3(string3);
364 StringTypeAdapter<StringType4> adapter4(string4);
365
366 UChar* buffer;
367 bool overflow = false;
368 unsigned length = adapter1.length();
369 sumWithOverflow(length, adapter2.length(), overflow);
370 sumWithOverflow(length, adapter3.length(), overflow);
371 sumWithOverflow(length, adapter4.length(), overflow);
372 if (overflow)
373 return 0;
374 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
375 if (!resultImpl)
376 return 0;
377
378 UChar* result = buffer;
379 adapter1.writeTo(result);
380 result += adapter1.length();
381 adapter2.writeTo(result);
382 result += adapter2.length();
383 adapter3.writeTo(result);
384 result += adapter3.length();
385 adapter4.writeTo(result);
386
387 return resultImpl;
388 }
389
390 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5>
391 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5)
392 {
393 StringTypeAdapter<StringType1> adapter1(string1);
394 StringTypeAdapter<StringType2> adapter2(string2);
395 StringTypeAdapter<StringType3> adapter3(string3);
396 StringTypeAdapter<StringType4> adapter4(string4);
397 StringTypeAdapter<StringType5> adapter5(string5);
398
399 UChar* buffer;
400 bool overflow = false;
401 unsigned length = adapter1.length();
402 sumWithOverflow(length, adapter2.length(), overflow);
403 sumWithOverflow(length, adapter3.length(), overflow);
404 sumWithOverflow(length, adapter4.length(), overflow);
405 sumWithOverflow(length, adapter5.length(), overflow);
406 if (overflow)
407 return 0;
408 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
409 if (!resultImpl)
410 return 0;
411
412 UChar* result = buffer;
413 adapter1.writeTo(result);
414 result += adapter1.length();
415 adapter2.writeTo(result);
416 result += adapter2.length();
417 adapter3.writeTo(result);
418 result += adapter3.length();
419 adapter4.writeTo(result);
420 result += adapter4.length();
421 adapter5.writeTo(result);
422
423 return resultImpl;
424 }
425
426 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6>
427 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6)
428 {
429 StringTypeAdapter<StringType1> adapter1(string1);
430 StringTypeAdapter<StringType2> adapter2(string2);
431 StringTypeAdapter<StringType3> adapter3(string3);
432 StringTypeAdapter<StringType4> adapter4(string4);
433 StringTypeAdapter<StringType5> adapter5(string5);
434 StringTypeAdapter<StringType6> adapter6(string6);
435
436 UChar* buffer;
437 bool overflow = false;
438 unsigned length = adapter1.length();
439 sumWithOverflow(length, adapter2.length(), overflow);
440 sumWithOverflow(length, adapter3.length(), overflow);
441 sumWithOverflow(length, adapter4.length(), overflow);
442 sumWithOverflow(length, adapter5.length(), overflow);
443 sumWithOverflow(length, adapter6.length(), overflow);
444 if (overflow)
445 return 0;
446 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
447 if (!resultImpl)
448 return 0;
449
450 UChar* result = buffer;
451 adapter1.writeTo(result);
452 result += adapter1.length();
453 adapter2.writeTo(result);
454 result += adapter2.length();
455 adapter3.writeTo(result);
456 result += adapter3.length();
457 adapter4.writeTo(result);
458 result += adapter4.length();
459 adapter5.writeTo(result);
460 result += adapter5.length();
461 adapter6.writeTo(result);
462
463 return resultImpl;
464 }
465
466 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7>
467 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7)
468 {
469 StringTypeAdapter<StringType1> adapter1(string1);
470 StringTypeAdapter<StringType2> adapter2(string2);
471 StringTypeAdapter<StringType3> adapter3(string3);
472 StringTypeAdapter<StringType4> adapter4(string4);
473 StringTypeAdapter<StringType5> adapter5(string5);
474 StringTypeAdapter<StringType6> adapter6(string6);
475 StringTypeAdapter<StringType7> adapter7(string7);
476
477 UChar* buffer;
478 bool overflow = false;
479 unsigned length = adapter1.length();
480 sumWithOverflow(length, adapter2.length(), overflow);
481 sumWithOverflow(length, adapter3.length(), overflow);
482 sumWithOverflow(length, adapter4.length(), overflow);
483 sumWithOverflow(length, adapter5.length(), overflow);
484 sumWithOverflow(length, adapter6.length(), overflow);
485 sumWithOverflow(length, adapter7.length(), overflow);
486 if (overflow)
487 return 0;
488 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
489 if (!resultImpl)
490 return 0;
491
492 UChar* result = buffer;
493 adapter1.writeTo(result);
494 result += adapter1.length();
495 adapter2.writeTo(result);
496 result += adapter2.length();
497 adapter3.writeTo(result);
498 result += adapter3.length();
499 adapter4.writeTo(result);
500 result += adapter4.length();
501 adapter5.writeTo(result);
502 result += adapter5.length();
503 adapter6.writeTo(result);
504 result += adapter6.length();
505 adapter7.writeTo(result);
506
507 return resultImpl;
508 }
509
510 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7, typename StringType8>
511 PassRefPtr<UStringImpl> tryMakeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8)
512 {
513 StringTypeAdapter<StringType1> adapter1(string1);
514 StringTypeAdapter<StringType2> adapter2(string2);
515 StringTypeAdapter<StringType3> adapter3(string3);
516 StringTypeAdapter<StringType4> adapter4(string4);
517 StringTypeAdapter<StringType5> adapter5(string5);
518 StringTypeAdapter<StringType6> adapter6(string6);
519 StringTypeAdapter<StringType7> adapter7(string7);
520 StringTypeAdapter<StringType8> adapter8(string8);
521
522 UChar* buffer;
523 bool overflow = false;
524 unsigned length = adapter1.length();
525 sumWithOverflow(length, adapter2.length(), overflow);
526 sumWithOverflow(length, adapter3.length(), overflow);
527 sumWithOverflow(length, adapter4.length(), overflow);
528 sumWithOverflow(length, adapter5.length(), overflow);
529 sumWithOverflow(length, adapter6.length(), overflow);
530 sumWithOverflow(length, adapter7.length(), overflow);
531 sumWithOverflow(length, adapter8.length(), overflow);
532 if (overflow)
533 return 0;
534 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer);
535 if (!resultImpl)
536 return 0;
537
538 UChar* result = buffer;
539 adapter1.writeTo(result);
540 result += adapter1.length();
541 adapter2.writeTo(result);
542 result += adapter2.length();
543 adapter3.writeTo(result);
544 result += adapter3.length();
545 adapter4.writeTo(result);
546 result += adapter4.length();
547 adapter5.writeTo(result);
548 result += adapter5.length();
549 adapter6.writeTo(result);
550 result += adapter6.length();
551 adapter7.writeTo(result);
552 result += adapter7.length();
553 adapter8.writeTo(result);
554
555 return resultImpl;
556 }
557
558 template<typename StringType1, typename StringType2>
559 UString makeString(StringType1 string1, StringType2 string2)
560 {
561 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2);
562 if (!resultImpl)
563 CRASH();
564 return resultImpl;
565 }
566
567 template<typename StringType1, typename StringType2, typename StringType3>
568 UString makeString(StringType1 string1, StringType2 string2, StringType3 string3)
569 {
570 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3);
571 if (!resultImpl)
572 CRASH();
573 return resultImpl;
574 }
575
576 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4>
577 UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4)
578 {
579 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4);
580 if (!resultImpl)
581 CRASH();
582 return resultImpl;
583 }
584
585 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5>
586 UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5)
587 {
588 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5);
589 if (!resultImpl)
590 CRASH();
591 return resultImpl;
592 }
593
594 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6>
595 UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6)
596 {
597 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6);
598 if (!resultImpl)
599 CRASH();
600 return resultImpl;
601 }
602
603 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7>
604 UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7)
605 {
606 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7);
607 if (!resultImpl)
608 CRASH();
609 return resultImpl;
610 }
611
612 template<typename StringType1, typename StringType2, typename StringType3, typename StringType4, typename StringType5, typename StringType6, typename StringType7, typename StringType8>
613 UString makeString(StringType1 string1, StringType2 string2, StringType3 string3, StringType4 string4, StringType5 string5, StringType6 string6, StringType7 string7, StringType8 string8)
614 {
615 PassRefPtr<UStringImpl> resultImpl = tryMakeString(string1, string2, string3, string4, string5, string6, string7, string8);
616 if (!resultImpl)
617 CRASH();
618 return resultImpl;
619 }
620
621} // namespace JSC
622
623namespace WTF {
624
625 template<typename T> struct DefaultHash;
626 template<typename T> struct StrHash;
627
628 template<> struct StrHash<JSC::UString::Rep*> {
629 static unsigned hash(const JSC::UString::Rep* key) { return key->hash(); }
630 static bool equal(const JSC::UString::Rep* a, const JSC::UString::Rep* b) { return ::equal(a, b); }
631 static const bool safeToCompareToEmptyOrDeleted = false;
632 };
633
634 template<> struct StrHash<RefPtr<JSC::UString::Rep> > : public StrHash<JSC::UString::Rep*> {
635 using StrHash<JSC::UString::Rep*>::hash;
636 static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->hash(); }
637 using StrHash<JSC::UString::Rep*>::equal;
638 static bool equal(const RefPtr<JSC::UString::Rep>& a, const RefPtr<JSC::UString::Rep>& b) { return ::equal(a.get(), b.get()); }
639 static bool equal(const JSC::UString::Rep* a, const RefPtr<JSC::UString::Rep>& b) { return ::equal(a, b.get()); }
640 static bool equal(const RefPtr<JSC::UString::Rep>& a, const JSC::UString::Rep* b) { return ::equal(a.get(), b); }
641
642 static const bool safeToCompareToEmptyOrDeleted = false;
643 };
644
645 template <> struct VectorTraits<JSC::UString> : SimpleClassVectorTraits
646 {
647 static const bool canInitializeWithMemset = true;
648 };
649
650} // namespace WTF
651
652#endif
Note: See TracBrowser for help on using the repository browser.