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

Side by Side Diff: Source/wtf/text/StringImpl.cpp

Issue 304273003: Simplify & optimize StringImpl::replace(UChar, UChar) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 4 * (C) 2001 Dirk Mueller ( mueller@kde.org )
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved.
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 if (matchLength > length()) 1522 if (matchLength > length())
1523 return false; 1523 return false;
1524 unsigned startOffset = length() - matchLength; 1524 unsigned startOffset = length() - matchLength;
1525 return equalInner(this, startOffset, matchString, matchLength, caseSensitive ); 1525 return equalInner(this, startOffset, matchString, matchLength, caseSensitive );
1526 } 1526 }
1527 1527
1528 PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) 1528 PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC)
1529 { 1529 {
1530 if (oldC == newC) 1530 if (oldC == newC)
1531 return this; 1531 return this;
1532 unsigned i; 1532
1533 for (i = 0; i != m_length; ++i) { 1533 if (find(oldC) == kNotFound)
1534 UChar c = is8Bit() ? characters8()[i] : characters16()[i];
1535 if (c == oldC)
1536 break;
1537 }
1538 if (i == m_length)
1539 return this; 1534 return this;
1540 1535
1536 unsigned i;
1541 if (is8Bit()) { 1537 if (is8Bit()) {
1542 if (oldC > 0xff)
1543 // Looking for a 16 bit char in an 8 bit string, we're done.
1544 return this;
1545
1546 if (newC <= 0xff) { 1538 if (newC <= 0xff) {
1547 LChar* data; 1539 LChar* data;
1548 LChar oldChar = static_cast<LChar>(oldC); 1540 LChar oldChar = static_cast<LChar>(oldC);
1549 LChar newChar = static_cast<LChar>(newC); 1541 LChar newChar = static_cast<LChar>(newC);
1550 1542
1551 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data); 1543 RefPtr<StringImpl> newImpl = createUninitialized(m_length, data);
1552 1544
1553 for (i = 0; i != m_length; ++i) { 1545 for (i = 0; i != m_length; ++i) {
1554 LChar ch = characters8()[i]; 1546 LChar ch = characters8()[i];
1555 if (ch == oldChar) 1547 if (ch == oldChar)
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 2099
2108 size_t StringImpl::sizeInBytes() const 2100 size_t StringImpl::sizeInBytes() const
2109 { 2101 {
2110 size_t size = length(); 2102 size_t size = length();
2111 if (!is8Bit()) 2103 if (!is8Bit())
2112 size *= 2; 2104 size *= 2;
2113 return size + sizeof(*this); 2105 return size + sizeof(*this);
2114 } 2106 }
2115 2107
2116 } // namespace WTF 2108 } // namespace WTF
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