Changeset 39747 in webkit for trunk/JavaScriptCore/runtime/UString.cpp
- Timestamp:
- Jan 9, 2009, 9:53:36 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.cpp
r38390 r39747 3 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 4 4 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 5 * Copyright (c) 2009, Google Inc. All rights reserved. 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 187 188 // reduce the possibility of it becoming zero due to ref/deref not being thread-safe. 188 189 static UChar sharedEmptyChar; 189 UString::Rep UString::Rep::null = { 0, 0, INT_MAX / 2, 0, 1, &UString::Rep::null, 0, 0, 0, 0, 0, 0 }; 190 UString::Rep UString::Rep::empty = { 0, 0, INT_MAX / 2, 0, 1, &UString::Rep::empty, 0, &sharedEmptyChar, 0, 0, 0, 0 }; 190 UString::Rep* UString::Rep::nullBaseString; 191 UString::Rep* UString::Rep::emptyBaseString; 192 UString* UString::nullUString; 193 194 void initializeStaticBaseString(int len, UChar* buf, UString::Rep& base) 195 { 196 base.offset = 0; 197 base.len = len; 198 base.rc = INT_MAX / 2; 199 base._hash = 0; 200 base.m_identifierTableAndFlags.setFlag(UString::Rep::StaticFlag); 201 base.baseString = &base; 202 base.buf = buf; 203 base.preCapacity = 0; 204 base.usedPreCapacity = 0; 205 base.capacity = 0; 206 base.usedCapacity = 0; 207 base.reportedCost = 0; 208 } 209 210 void initializeUString() 211 { 212 UString::Rep::nullBaseString = new UString::Rep; 213 initializeStaticBaseString(0, 0, *UString::Rep::nullBaseString); 214 215 UString::Rep::emptyBaseString = new UString::Rep; 216 initializeStaticBaseString(0, &sharedEmptyChar, *UString::Rep::emptyBaseString); 217 218 UString::nullUString = new UString; 219 } 191 220 192 221 static char* statBuffer = 0; // Only used for debugging via UString::ascii(). … … 206 235 r->rc = 1; 207 236 r->_hash = 0; 208 r->m_identifierTable = 0;209 237 r->baseString = r; 210 238 r->reportedCost = 0; … … 238 266 r->rc = 1; 239 267 r->_hash = 0; 240 r->m_identifierTable = 0;241 268 r->baseString = base.releaseRef(); 242 269 r->reportedCost = 0; … … 256 283 { 257 284 if (!string) 258 return &UString::Rep::null ;285 return &UString::Rep::null(); 259 286 260 287 size_t length = strlen(string); … … 262 289 UChar* p = buffer.data(); 263 290 if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length)) 264 return &UString::Rep::null ;291 return &UString::Rep::null(); 265 292 266 293 return UString::Rep::createCopying(buffer.data(), p - buffer.data()); … … 495 522 { 496 523 if (!c) 497 return &UString::Rep::null ;524 return &UString::Rep::null(); 498 525 499 526 if (!c[0]) 500 return &UString::Rep::empty ;527 return &UString::Rep::empty(); 501 528 502 529 size_t length = strlen(c); 503 530 UChar* d = allocChars(length); 504 531 if (!d) 505 return &UString::Rep::null ;532 return &UString::Rep::null(); 506 533 else { 507 534 for (size_t i = 0; i < length; i++) … … 520 547 { 521 548 if (length == 0) 522 m_rep = &Rep::empty ;549 m_rep = &Rep::empty(); 523 550 else 524 551 m_rep = Rep::createCopying(c, length); … … 528 555 { 529 556 if (length == 0) 530 m_rep = &Rep::empty ;557 m_rep = &Rep::empty(); 531 558 else if (copy) 532 559 m_rep = Rep::createCopying(c, length); … … 538 565 { 539 566 if (!buffer.size()) 540 m_rep = &Rep::empty ;567 m_rep = &Rep::empty(); 541 568 else 542 569 m_rep = Rep::createCopying(buffer.data(), buffer.size()); … … 562 589 // this is direct and has refcount of 1 (so we can just alter it directly) 563 590 if (!expandCapacity(rep.get(), thisOffset + length)) 564 rep = &UString::Rep::null ;591 rep = &UString::Rep::null(); 565 592 if (rep->data()) { 566 593 copyChars(rep->data() + thisSize, tData, tSize); … … 571 598 // this reaches the end of the buffer - extend it if it's long enough to append to 572 599 if (!expandCapacity(rep.get(), thisOffset + length)) 573 rep = &UString::Rep::null ;600 rep = &UString::Rep::null(); 574 601 if (rep->data()) { 575 602 copyChars(rep->data() + thisSize, tData, tSize); … … 581 608 UChar* d = allocChars(newCapacity); 582 609 if (!d) 583 rep = &UString::Rep::null ;610 rep = &UString::Rep::null(); 584 611 else { 585 612 copyChars(d, rep->data(), thisSize); … … 636 663 UChar* d = allocChars(newCapacity); 637 664 if (!d) 638 rep = &UString::Rep::null ;665 rep = &UString::Rep::null(); 639 666 else { 640 667 copyChars(d, rep->data(), thisSize); … … 832 859 } 833 860 834 const UString& UString::null()835 {836 static UString* n = new UString; // Should be called from main thread at least once to be safely initialized.837 return *n;838 }839 840 861 UString UString::from(int i) 841 862 { … … 1186 1207 { 1187 1208 if (!c) { 1188 m_rep = &Rep::null ;1209 m_rep = &Rep::null(); 1189 1210 return *this; 1190 1211 } 1191 1212 1192 1213 if (!c[0]) { 1193 m_rep = &Rep::empty ;1214 m_rep = &Rep::empty(); 1194 1215 return *this; 1195 1216 } … … 1627 1648 NEVER_INLINE void UString::makeNull() 1628 1649 { 1629 m_rep = &Rep::null ;1650 m_rep = &Rep::null(); 1630 1651 } 1631 1652 … … 1633 1654 NEVER_INLINE UString::Rep* UString::nullRep() 1634 1655 { 1635 return &Rep::null ;1656 return &Rep::null(); 1636 1657 } 1637 1658
Note:
See TracChangeset
for help on using the changeset viewer.