Changeset 54464 in webkit for trunk/JavaScriptCore/runtime/UString.cpp
- Timestamp:
- Feb 6, 2010, 12:55:31 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.cpp
r53456 r54464 150 150 // reduce the possibility of it becoming zero due to ref/deref not being thread-safe. 151 151 static UChar sharedEmptyChar; 152 UStringImpl* UStringImpl::s_null;153 152 UStringImpl* UStringImpl::s_empty; 154 UString* UString::nullUString; 153 154 UString::Rep* UString::s_nullRep; 155 UString* UString::s_nullUString; 155 156 156 157 void initializeUString() 157 158 { 158 UStringImpl::s_null = new UStringImpl(0, 0, UStringImpl::ConstructStaticString);159 159 UStringImpl::s_empty = new UStringImpl(&sharedEmptyChar, 0, UStringImpl::ConstructStaticString); 160 UString::nullUString = new UString; 161 } 162 163 static PassRefPtr<UString::Rep> createRep(const char* c) 164 { 165 if (!c) 166 return &UString::Rep::null(); 167 168 if (!c[0]) 169 return &UString::Rep::empty(); 170 171 size_t length = strlen(c); 172 UChar* d; 173 PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d); 174 if (!result) 175 return &UString::Rep::null(); 176 177 for (size_t i = 0; i < length; i++) 178 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 179 return result; 180 } 181 182 static inline PassRefPtr<UString::Rep> createRep(const char* c, int length) 183 { 184 if (!c) 185 return &UString::Rep::null(); 186 187 if (!length) 188 return &UString::Rep::empty(); 189 190 UChar* d; 191 PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d); 192 if (!result) 193 return &UString::Rep::null(); 194 195 for (int i = 0; i < length; i++) 196 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 197 return result; 160 161 UString::s_nullRep = new UStringImpl(0, 0, UStringImpl::ConstructStaticString); 162 UString::s_nullUString = new UString; 198 163 } 199 164 200 165 UString::UString(const char* c) 201 : m_rep( createRep(c))166 : m_rep(Rep::create(c)) 202 167 { 203 168 } 204 169 205 170 UString::UString(const char* c, int length) 206 : m_rep( createRep(c, length))171 : m_rep(Rep::create(c, length)) 207 172 { 208 173 } … … 460 425 { 461 426 if (!c) { 462 m_rep = &Rep::null();427 m_rep = s_nullRep; 463 428 return *this; 464 429 } … … 476 441 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 477 442 } else 478 m akeNull();443 m_rep = s_nullRep;; 479 444 480 445 return *this; … … 889 854 } 890 855 891 // For use in error handling code paths -- having this not be inlined helps avoid PIC branches to fetch the global on Mac OS X.892 NEVER_INLINE void UString::makeNull()893 {894 m_rep = &Rep::null();895 }896 897 // For use in error handling code paths -- having this not be inlined helps avoid PIC branches to fetch the global on Mac OS X.898 NEVER_INLINE UString::Rep* UString::nullRep()899 {900 return &Rep::null();901 }902 903 856 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.