Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1289)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/Character.cpp

Issue 1545073002: Make Character::isCJKIdeographOrSymbol() faster for common characters (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor simplification Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 return valueInIntervalList(cjkIdeographRanges, c); 336 return valueInIntervalList(cjkIdeographRanges, c);
337 } 337 }
338 338
339 bool Character::isCJKIdeographOrSymbol(UChar32 c) 339 bool Character::isCJKIdeographOrSymbol(UChar32 c)
340 { 340 {
341 // Likely common case 341 // Likely common case
342 if (c < 0x2C7) 342 if (c < 0x2C7)
343 return false; 343 return false;
344 344
345 // Hash lookup for isolated symbols (those not part of a contiguous range)
346 static HashSet<UChar32>* cjkIsolatedSymbols = 0;
347 if (!cjkIsolatedSymbols) {
348 cjkIsolatedSymbols = new HashSet<UChar32>();
349 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cjkIsolatedSymbolsArray); ++i)
350 cjkIsolatedSymbols->add(cjkIsolatedSymbolsArray[i]);
351 }
352 if (cjkIsolatedSymbols->contains(c))
353 return true;
354
355 if (isCJKIdeograph(c)) 345 if (isCJKIdeograph(c))
356 return true; 346 return true;
357 347
358 static const UChar32 cjkSymbolRanges[] = { 348 static const UChar32 cjkSymbolRanges[] = {
359 0x2156, 0x215A, 349 0x2156, 0x215A,
360 0x2160, 0x216B, 350 0x2160, 0x216B,
361 0x2170, 0x217B, 351 0x2170, 0x217B,
362 0x23BE, 0x23CC, 352 0x23BE, 0x23CC,
363 0x2460, 0x2492, 353 0x2460, 0x2492,
364 0x249C, 0x24FF, 354 0x249C, 0x24FF,
(...skipping 21 matching lines...) Expand all
386 0xFF0E, 0xFF1A, 376 0xFF0E, 0xFF1A,
387 0xFF1F, 0xFFEF, 377 0xFF1F, 0xFFEF,
388 // Emoji. 378 // Emoji.
389 0x1F110, 0x1F129, 379 0x1F110, 0x1F129,
390 0x1F130, 0x1F149, 380 0x1F130, 0x1F149,
391 0x1F150, 0x1F169, 381 0x1F150, 0x1F169,
392 0x1F170, 0x1F189, 382 0x1F170, 0x1F189,
393 0x1F200, 0x1F6FF 383 0x1F200, 0x1F6FF
394 }; 384 };
395 385
396 return valueInIntervalList(cjkSymbolRanges, c); 386 if (c >= cjkSymbolRanges[0]
387 && c <= cjkSymbolRanges[WTF_ARRAY_LENGTH(cjkSymbolRanges) - 1]
388 && valueInIntervalList(cjkSymbolRanges, c)) {
389 return true;
390 }
391
392 if (c < 0x2020 && c > 0x2D9)
393 return false;
394
395 // Hash lookup for isolated symbols (those not part of a contiguous range)
396 static HashSet<UChar32>* cjkIsolatedSymbols = 0;
397 if (!cjkIsolatedSymbols) {
398 cjkIsolatedSymbols = new HashSet<UChar32>();
399 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cjkIsolatedSymbolsArray); ++i)
400 cjkIsolatedSymbols->add(cjkIsolatedSymbolsArray[i]);
401 }
402 return cjkIsolatedSymbols->contains(c);
397 } 403 }
398 404
399 unsigned Character::expansionOpportunityCount(const LChar* characters, size_t le ngth, TextDirection direction, bool& isAfterExpansion, const TextJustify textJus tify) 405 unsigned Character::expansionOpportunityCount(const LChar* characters, size_t le ngth, TextDirection direction, bool& isAfterExpansion, const TextJustify textJus tify)
400 { 406 {
401 unsigned count = 0; 407 unsigned count = 0;
402 if (textJustify == TextJustifyDistribute) { 408 if (textJustify == TextJustifyDistribute) {
403 isAfterExpansion = true; 409 isAfterExpansion = true;
404 return length; 410 return length;
405 } 411 }
406 412
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 519 }
514 520
515 bool Character::isCommonOrInheritedScript(UChar32 character) 521 bool Character::isCommonOrInheritedScript(UChar32 character)
516 { 522 {
517 UErrorCode status = U_ZERO_ERROR; 523 UErrorCode status = U_ZERO_ERROR;
518 UScriptCode script = uscript_getScript(character, &status); 524 UScriptCode script = uscript_getScript(character, &status);
519 return U_SUCCESS(status) && (script == USCRIPT_COMMON || script == USCRIPT_I NHERITED); 525 return U_SUCCESS(status) && (script == USCRIPT_COMMON || script == USCRIPT_I NHERITED);
520 } 526 }
521 527
522 } // namespace blink 528 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698