Changeset 162185 in webkit for trunk/Source/JavaScriptCore/API/OpaqueJSString.cpp
- Timestamp:
- Jan 16, 2014, 10:50:26 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/OpaqueJSString.cpp
r157688 r162185 37 37 if (!string.isNull()) 38 38 return adoptRef(new OpaqueJSString(string)); 39 return 0; 39 return nullptr; 40 } 41 42 OpaqueJSString::~OpaqueJSString() 43 { 44 if (UChar* characters = m_characters) { 45 // m_characters is put in a local here to avoid an extra atomic load. 46 fastFree(static_cast<void*>(characters)); 47 } 40 48 } 41 49 … … 62 70 return Identifier(vm, m_string.characters16(), m_string.length()); 63 71 } 72 73 const UChar* OpaqueJSString::characters() 74 { 75 if (!this) 76 return nullptr; 77 78 // m_characters is put in a local here to avoid an extra atomic load. 79 UChar* characters = m_characters; 80 if (characters) 81 return characters; 82 83 unsigned length = m_string.length(); 84 UChar* newCharacters = static_cast<UChar*>(fastMalloc(length * sizeof(UChar))); 85 86 if (m_string.is8Bit()) { 87 for (size_t i = 0; i < length; ++i) 88 newCharacters[i] = m_string.characters8()[i]; 89 } else 90 memcpy(newCharacters, m_string.characters16(), length * sizeof(UChar)); 91 92 if (!m_characters.compare_exchange_strong(characters, newCharacters)) { 93 fastFree(newCharacters); 94 return characters; 95 } 96 97 return newCharacters; 98 } 99 100 bool OpaqueJSString::equal(const OpaqueJSString* a, const OpaqueJSString* b) 101 { 102 if (a == b) 103 return true; 104 105 if (!a || !b) 106 return false; 107 108 return a->m_string == b->m_string; 109 } 110 111
Note:
See TracChangeset
for help on using the changeset viewer.