OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 Charset, | 318 Charset, |
319 Pragma, | 319 Pragma, |
320 }; | 320 }; |
321 | 321 |
322 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList& attributes
) | 322 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList& attributes
) |
323 { | 323 { |
324 bool gotPragma = false; | 324 bool gotPragma = false; |
325 Mode mode = None; | 325 Mode mode = None; |
326 String charset; | 326 String charset; |
327 | 327 |
328 for (HTMLAttributeList::const_iterator iter = attributes.begin(); iter != at
tributes.end(); ++iter) { | 328 for (const auto& htmlAttribute : attributes) { |
329 const String& attributeName = iter->first; | 329 const String& attributeName = htmlAttribute.first; |
330 const String& attributeValue = AtomicString(iter->second); | 330 const String& attributeValue = AtomicString(htmlAttribute.second); |
331 | 331 |
332 if (threadSafeMatch(attributeName, http_equivAttr)) { | 332 if (threadSafeMatch(attributeName, http_equivAttr)) { |
333 if (equalIgnoringCase(attributeValue, "content-type")) | 333 if (equalIgnoringCase(attributeValue, "content-type")) |
334 gotPragma = true; | 334 gotPragma = true; |
335 } else if (charset.isEmpty()) { | 335 } else if (charset.isEmpty()) { |
336 if (threadSafeMatch(attributeName, charsetAttr)) { | 336 if (threadSafeMatch(attributeName, charsetAttr)) { |
337 charset = attributeValue; | 337 charset = attributeValue; |
338 mode = Charset; | 338 mode = Charset; |
339 } else if (threadSafeMatch(attributeName, contentAttr)) { | 339 } else if (threadSafeMatch(attributeName, contentAttr)) { |
340 charset = extractCharset(attributeValue); | 340 charset = extractCharset(attributeValue); |
(...skipping 26 matching lines...) Expand all Loading... |
367 bool threadSafeMatch(const String& localName, const QualifiedName& qName) | 367 bool threadSafeMatch(const String& localName, const QualifiedName& qName) |
368 { | 368 { |
369 return threadSafeEqual(localName.impl(), qName.localName().impl()); | 369 return threadSafeEqual(localName.impl(), qName.localName().impl()); |
370 } | 370 } |
371 | 371 |
372 template<typename CharType> | 372 template<typename CharType> |
373 inline StringImpl* findStringIfStatic(const CharType* characters, unsigned lengt
h) | 373 inline StringImpl* findStringIfStatic(const CharType* characters, unsigned lengt
h) |
374 { | 374 { |
375 // We don't need to try hashing if we know the string is too long. | 375 // We don't need to try hashing if we know the string is too long. |
376 if (length > StringImpl::highestStaticStringLength()) | 376 if (length > StringImpl::highestStaticStringLength()) |
377 return 0; | 377 return nullptr; |
378 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. | 378 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. |
379 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length)
; | 379 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length)
; |
380 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); | 380 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); |
381 ASSERT(!table.isEmpty()); | 381 ASSERT(!table.isEmpty()); |
382 | 382 |
383 WTF::StaticStringsTable::const_iterator it = table.find(hash); | 383 WTF::StaticStringsTable::const_iterator it = table.find(hash); |
384 if (it == table.end()) | 384 if (it == table.end()) |
385 return 0; | 385 return nullptr; |
386 // It's possible to have hash collisions between arbitrary strings and | 386 // It's possible to have hash collisions between arbitrary strings and |
387 // known identifiers (e.g. "bvvfg" collides with "script"). | 387 // known identifiers (e.g. "bvvfg" collides with "script"). |
388 // However ASSERTs in StringImpl::createStatic guard against there ever bein
g collisions | 388 // However ASSERTs in StringImpl::createStatic guard against there ever bein
g collisions |
389 // between static strings. | 389 // between static strings. |
390 if (!equal(it->value, characters, length)) | 390 if (!equal(it->value, characters, length)) |
391 return 0; | 391 return nullptr; |
392 return it->value; | 392 return it->value; |
393 } | 393 } |
394 | 394 |
395 String attemptStaticStringCreation(const LChar* characters, size_t size) | 395 String attemptStaticStringCreation(const LChar* characters, size_t size) |
396 { | 396 { |
397 String string(findStringIfStatic(characters, size)); | 397 String string(findStringIfStatic(characters, size)); |
398 if (string.impl()) | 398 if (string.impl()) |
399 return string; | 399 return string; |
400 return String(characters, size); | 400 return String(characters, size); |
401 } | 401 } |
402 | 402 |
403 String attemptStaticStringCreation(const UChar* characters, size_t size, Charact
erWidth width) | 403 String attemptStaticStringCreation(const UChar* characters, size_t size, Charact
erWidth width) |
404 { | 404 { |
405 String string(findStringIfStatic(characters, size)); | 405 String string(findStringIfStatic(characters, size)); |
406 if (string.impl()) | 406 if (string.impl()) |
407 return string; | 407 return string; |
408 if (width == Likely8Bit) | 408 if (width == Likely8Bit) |
409 string = StringImpl::create8BitIfPossible(characters, size); | 409 string = StringImpl::create8BitIfPossible(characters, size); |
410 else if (width == Force8Bit) | 410 else if (width == Force8Bit) |
411 string = String::make8BitFrom16BitSource(characters, size); | 411 string = String::make8BitFrom16BitSource(characters, size); |
412 else | 412 else |
413 string = String(characters, size); | 413 string = String(characters, size); |
414 | 414 |
415 return string; | 415 return string; |
416 } | 416 } |
417 | 417 |
418 } | 418 } |
OLD | NEW |