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

Side by Side Diff: trunk/src/base/i18n/streaming_utf8_validator_perftest.cc

Issue 198163004: Revert 257524 "Move IsStringASCII/UTF8 to base namespace." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/base/command_line.cc ('k') | trunk/src/base/strings/string_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // All data that is passed through a WebSocket with type "Text" needs to be 5 // All data that is passed through a WebSocket with type "Text" needs to be
6 // validated as UTF8. Since this is done on the IO thread, it needs to be 6 // validated as UTF8. Since this is done on the IO thread, it needs to be
7 // reasonably fast. 7 // reasonably fast.
8 8
9 // We are only interested in the performance on valid UTF8. Invalid UTF8 will 9 // We are only interested in the performance on valid UTF8. Invalid UTF8 will
10 // result in a connection failure, so is unlikely to become a source of 10 // result in a connection failure, so is unlikely to become a source of
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // the results will not be meaningful with sequences containing 49 // the results will not be meaningful with sequences containing
50 // top-bit-set bytes. 50 // top-bit-set bytes.
51 bool IsString7Bit(const std::string& s) { 51 bool IsString7Bit(const std::string& s) {
52 for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { 52 for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
53 if (*it & 0x80) 53 if (*it & 0x80)
54 return false; 54 return false;
55 } 55 }
56 return true; 56 return true;
57 } 57 }
58 58
59 bool IsStringUTF8(const std::string& s) {
60 return base::IsStringUTF8(s);
61 }
62
63 // Assumes that |previous| is a valid UTF-8 sequence, and attempts to return 59 // Assumes that |previous| is a valid UTF-8 sequence, and attempts to return
64 // the next one. Is just barely smart enough to iterate through the ranges 60 // the next one. Is just barely smart enough to iterate through the ranges
65 // defined about. 61 // defined about.
66 std::string NextUtf8Sequence(const std::string& previous) { 62 std::string NextUtf8Sequence(const std::string& previous) {
67 DCHECK(StreamingUtf8Validator::Validate(previous)); 63 DCHECK(StreamingUtf8Validator::Validate(previous));
68 std::string next = previous; 64 std::string next = previous;
69 for (int i = static_cast<int>(previous.length() - 1); i >= 0; --i) { 65 for (int i = static_cast<int>(previous.length() - 1); i >= 0; --i) {
70 // All bytes in a UTF-8 sequence except the first one are 66 // All bytes in a UTF-8 sequence except the first one are
71 // constrained to the range 0x80 to 0xbf, inclusive. When we 67 // constrained to the range 0x80 to 0xbf, inclusive. When we
72 // increment past 0xbf, we carry into the previous byte. 68 // increment past 0xbf, we carry into the previous byte.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d", 225 RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d",
230 base::Bind(ConstructRangedTestString, 226 base::Bind(ConstructRangedTestString,
231 kFourByteSeqRangeStart, 227 kFourByteSeqRangeStart,
232 kFourByteSeqRangeEnd), 228 kFourByteSeqRangeEnd),
233 kTestFunctions, 229 kTestFunctions,
234 2); 230 2);
235 } 231 }
236 232
237 } // namespace 233 } // namespace
238 } // namespace base 234 } // namespace base
OLDNEW
« no previous file with comments | « trunk/src/base/command_line.cc ('k') | trunk/src/base/strings/string_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698