Changeset 1791 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Aug 9, 2002, 9:31:50 PM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r1789 r1791 30 30 #include <typeinfo> 31 31 #endif 32 #ifdef APPLE_CHANGES33 #include <pthread.h>34 #endif35 32 36 33 namespace KJS { -
trunk/JavaScriptCore/kjs/regexp.cpp
r1623 r1791 115 115 return UString::null; // don't rely on the return value if you pass ovector==0 116 116 #else 117 #ifdef APPLE_CHANGES118 117 const uint maxMatch = 10; 119 #else120 const int maxMatch = 10;121 #endif122 118 regmatch_t rmatch[maxMatch]; 123 119 … … 136 132 // map rmatch array to ovector used in PCRE case 137 133 nrSubPatterns = 0; 138 #ifdef APPLE_CHANGES139 134 for(uint j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++) 140 #else141 for(int j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++)142 #endif143 135 nrSubPatterns++; 144 136 int ovecsize = (nrSubPatterns+1)*3; // see above 145 137 *ovector = new int[ovecsize]; 146 #ifdef APPLE_CHANGES147 138 for (uint j = 0; j < nrSubPatterns + 1; j++) { 148 #else149 for (int j = 0; j < nrSubPatterns + 1; j++) {150 #endif151 139 if (j>maxMatch) 152 140 break; 153 141 (*ovector)[2*j] = rmatch[j].rm_so + i; 154 142 (*ovector)[2*j+1] = rmatch[j].rm_eo + i; 155 #ifdef APPLE_CHANGES156 } // balance extra { so we don't confuse prepare-ChangeLog157 #else158 143 } 159 #endif160 144 #endif 161 145 -
trunk/JavaScriptCore/kjs/ustring.cpp
r1623 r1791 104 104 } 105 105 106 CString &CString::operator+=(const CString &str)107 {108 return append(str.c_str());109 }110 111 106 int CString::size() const 112 107 { … … 120 115 121 116 UChar UChar::null; 122 #ifdef APPLE_CHANGES123 117 UString::Rep UString::Rep::null = { 0, 0, 0, 1 }; 124 #else125 UString::Rep UString::Rep::null = { 0, 0, 1 };126 #endif127 118 UString UString::null; 128 #ifdef APPLE_CHANGES 129 static pthread_once_t statBufferKeyOnce = PTHREAD_ONCE_INIT; 130 static pthread_key_t statBufferKey; 131 #else 132 static char *statBuffer = 0L; 133 #endif 119 const int normalStatBufferSize = 4096; 120 static char *statBuffer = 0; 121 static int statBufferSize = 0; 134 122 135 123 UChar::UChar(const UCharReference &c) … … 140 128 UChar UChar::toLower() const 141 129 { 142 // ### properly supp rot unicode tolower130 // ### properly support unicode tolower 143 131 if (uc >= 256 || islower(uc)) 144 132 return *this; 145 133 146 return UChar(tolower(uc));134 return (unsigned char)tolower(uc); 147 135 } 148 136 … … 152 140 return *this; 153 141 154 return UChar(toupper(uc));142 return (unsigned char)toupper(uc); 155 143 } 156 144 … … 177 165 r->dat = d; 178 166 r->len = l; 179 #ifdef APPLE_CHANGES180 167 r->capacity = l; 181 #endif182 168 r->rc = 1; 183 169 … … 194 180 { 195 181 UChar *d = new UChar[1]; 196 d[0] = UChar(0, c);182 d[0] = c; 197 183 rep = Rep::create(d, 1); 198 184 } … … 200 186 UString::UString(const char *c) 201 187 { 202 attach(&Rep::null); 203 operator=(c); 188 if (!c) { 189 attach(&Rep::null); 190 return; 191 } 192 int length = strlen(c); 193 UChar *d = new UChar[length]; 194 for (int i = 0; i < length; i++) 195 d[i].uc = c[i]; 196 rep = Rep::create(d, length); 204 197 } 205 198 … … 227 220 } 228 221 229 UString::~UString() 230 { 231 release(); 222 UString::UString(const UString &a, const UString &b) 223 { 224 int aSize = a.size(); 225 int bSize = b.size(); 226 UChar *d = new UChar[aSize + bSize]; 227 memcpy(d, a.data(), aSize * sizeof(UChar)); 228 memcpy(d + aSize, b.data(), bSize * sizeof(UChar)); 229 rep = Rep::create(d, aSize + bSize); 232 230 } 233 231 … … 275 273 UString &UString::append(const UString &t) 276 274 { 277 #ifdef APPLE_CHANGES278 275 int l = size(); 279 276 int tLen = t.size(); … … 292 289 rep = Rep::create(n, newLen); 293 290 rep->capacity = newCapacity; 294 #else295 int l = size();296 UChar *n = new UChar[l+t.size()];297 memcpy(n, data(), l * sizeof(UChar));298 memcpy(n+l, t.data(), t.size() * sizeof(UChar));299 release();300 rep = Rep::create(n, l + t.size());301 #endif302 291 303 292 return *this; … … 306 295 CString UString::cstring() const 307 296 { 308 return CString(ascii()); 309 } 310 311 #ifdef APPLE_CHANGES 312 static void statBufferKeyCleanup(void *statBuffer) 313 { 314 if (statBuffer != NULL) 315 delete [] (char *)statBuffer; 316 } 317 318 static void statBufferKeyInit(void) 319 { 320 pthread_key_create(&statBufferKey, statBufferKeyCleanup); 321 } 322 #endif 297 return ascii(); 298 } 323 299 324 300 char *UString::ascii() const 325 301 { 326 #ifdef APPLE_CHANGES 327 pthread_once(&statBufferKeyOnce, statBufferKeyInit); 328 char *statBuffer = (char *)pthread_getspecific(statBufferKey); 329 #endif 330 if (statBuffer) 302 // Never make the buffer smaller than normalStatBufferSize. 303 // Thus we almost never need to reallocate. 304 int length = size(); 305 int neededSize = length + 1; 306 if (neededSize < normalStatBufferSize) { 307 neededSize = normalStatBufferSize; 308 } 309 if (neededSize != statBufferSize) { 331 310 delete [] statBuffer; 332 333 statBuffer = new char[size()+1]; 334 for(int i = 0; i < size(); i++) 335 statBuffer[i] = data()[i].low(); 336 statBuffer[size()] = '\0'; 337 338 #ifdef APPLE_CHANGES 339 pthread_setspecific(statBufferKey, statBuffer); 340 #endif 311 statBuffer = new char [neededSize]; 312 statBufferSize = neededSize; 313 } 314 315 const UChar *p = data(); 316 char *q = statBuffer; 317 const UChar *limit = p + length; 318 while (p != limit) { 319 *q = p->uc; 320 ++p; 321 ++q; 322 } 323 *q = '\0'; 324 341 325 return statBuffer; 342 326 } … … 346 330 { 347 331 delete [] statBuffer; 348 statBuffer = 0L; 332 statBuffer = 0; 333 statBufferSize = 0; 349 334 } 350 335 #endif … … 352 337 UString &UString::operator=(const char *c) 353 338 { 354 #ifdef APPLE_CHANGES355 339 int l = c ? strlen(c) : 0; 356 340 UChar *d; … … 363 347 } 364 348 for (int i = 0; i < l; i++) 365 d[i].uc = (uchar)c[i];366 #else367 release();368 int l = c ? strlen(c) : 0;369 370 UChar *d = new UChar[l];371 for (int i = 0; i < l; i++)372 349 d[i].uc = c[i]; 373 rep = Rep::create(d, l);374 #endif375 350 376 351 return *this; … … 386 361 } 387 362 388 UString &UString::operator+=(const UString &s)389 {390 return append(s);391 }392 393 363 bool UString::is8Bit() const 394 364 { 395 365 const UChar *u = data(); 396 for(int i = 0; i < size(); i++, u++) 366 const UChar *limit = u + size(); 367 while (u < limit) { 397 368 if (u->uc > 0xFF) 398 369 return false; 370 ++u; 371 } 399 372 400 373 return true; … … 422 395 return NaN; 423 396 424 CString str = cstring(); 425 const char *c = str.c_str(); 397 const char *c = ascii(); 426 398 427 399 // skip leading white space … … 615 587 return (l1 < l2); 616 588 } 617 618 UString KJS::operator+(const UString& s1, const UString& s2)619 {620 UString tmp(s1);621 tmp.append(s2);622 623 return tmp;624 } -
trunk/JavaScriptCore/kjs/ustring.h
r1623 r1791 56 56 */ 57 57 struct UChar { 58 #ifdef APPLE_CHANGES59 58 /** 60 59 * Construct a character with uninitialized value. 61 60 */ 62 #else63 /**64 * Construct a character with value 0.65 */66 #endif67 61 UChar(); 68 62 /** … … 76 70 * @param u 16 bit Unicode value 77 71 */ 72 UChar(char u); 73 UChar(unsigned char u); 78 74 UChar(unsigned short u); 79 75 UChar(const UCharReference &c); … … 85 81 * @return The lower byte of the character. 86 82 */ 87 unsigned char low() const { return uc & 0xFF; }83 unsigned char low() const { return uc; } 88 84 /** 89 85 * @return the 16 bit Unicode value of the character … … 113 109 }; 114 110 115 #ifdef APPLE_CHANGES116 inline UChar::UChar() : uc(0) { }117 #else118 111 inline UChar::UChar() { } 119 #endif120 112 inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { } 113 inline UChar::UChar(char u) : uc((unsigned char)u) { } 114 inline UChar::UChar(unsigned char u) : uc(u) { } 121 115 inline UChar::UChar(unsigned short u) : uc(u) { } 122 116 … … 190 184 CString &operator=(const char *c); 191 185 CString &operator=(const CString &); 192 CString &operator+=(const CString & );186 CString &operator+=(const CString &c) { return append(c); } 193 187 194 188 int size() const; … … 219 213 UChar *dat; 220 214 int len; 221 #ifdef APPLE_CHANGES222 215 int capacity; 223 #endif224 216 int rc; 225 217 static Rep null; … … 244 236 */ 245 237 UString(const UChar *c, int length); 246 #ifdef APPLE_CHANGES247 238 /** 248 239 * If copy is false the string data will be adopted. … … 251 242 * Behaviour defaults to a deep copy if copy is true. 252 243 */ 253 #else254 /**255 * If copy is false a shallow copy of the string will be created. That256 * means that the data will NOT be copied and you'll have to guarantee that257 * it doesn't get deleted during the lifetime of the UString object.258 * Behaviour defaults to a deep copy if copy is true.259 */260 #endif261 244 UString(UChar *c, int length, bool copy); 262 245 /** … … 277 260 UString(const DOM::DOMString &); 278 261 /** 262 * Concatenation constructor. Makes operator+ more efficient. 263 */ 264 UString(const UString &, const UString &); 265 /** 279 266 * Destructor. If this handle was the only one holding a reference to the 280 267 * string the data will be freed. 281 268 */ 282 ~UString() ;269 ~UString() { release(); } 283 270 284 271 /** … … 336 323 * Appends the specified string. 337 324 */ 338 UString &operator+=(const UString &s) ;325 UString &operator+=(const UString &s) { return append(s); } 339 326 340 327 /** … … 435 422 } 436 423 bool operator==(const CString& s1, const CString& s2); 437 UString operator+(const UString& s1, const UString& s2); 424 inline UString operator+(const UString& s1, const UString& s2) { 425 return UString(s1, s2); 426 } 438 427 439 428 }; // namespace -
trunk/JavaScriptCore/kjs/value.h
r1326 r1791 95 95 virtual ~ValueImp(); 96 96 97 #ifdef APPLE_CHANGES98 // The collector lock is not locked around the ref() and unref()99 // methods for the following reasons:100 //101 // - The only cases where changing the refcount could possibly102 // affect the collector's behavior is incrementing from 0 to 1,103 // and decrementing from 1 to 0.104 //105 // - In the 0 to 1 case, the GC allowed flag will always be off106 // beforehand, and set right afterwards. And setting it grabs the107 // collector lock. So if this happens in the middle of GC, the108 // collector will see either a refcount 0 GC not allowed object,109 // or a refcount 1 GC not allowed object, and these cases are110 // treated exactly the same.111 //112 // - In the 1 to 0 case, the only possible bad effect is that the113 // object will live for one GC cycle longer than it should have114 // to, which is really not so bad.115 //116 // - In theory on some platforms increment or decrement could make117 // other threads see intermediate values that are different from118 // both the start and end value. If that turns out to really be119 // the case we will have to reconsider this scheme.120 #endif121 97 inline ValueImp* ref() { refcount++; return this; } 122 98 inline bool deref() { return (!--refcount); }
Note:
See TracChangeset
for help on using the changeset viewer.