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

Unified Diff: runtime/vm/unicode_test.cc

Issue 2952193002: VM: Speed up output of UTF8 for 1-byte strings.
Patch Set: Add test that would have caught bug pointed out by Slava Created 3 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/unicode.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/unicode_test.cc
diff --git a/runtime/vm/unicode_test.cc b/runtime/vm/unicode_test.cc
index f2ce998d6467e3d19a828b4cea67d33a83bdfd1f..0af271cd22d754df2b8a761d7fae454491b551db 100644
--- a/runtime/vm/unicode_test.cc
+++ b/runtime/vm/unicode_test.cc
@@ -8,6 +8,25 @@
namespace dart {
+TEST_CASE(Utf8Encode) {
+ const intptr_t kInputLen = 3;
+ const uint16_t kInput[kInputLen] = {0xe6, 0xe7, 0xe8}; // æøå
+ const String& input = String::Handle(String::FromUTF16(kInput, kInputLen));
+ static const uintptr_t kBufferLength = 10;
+ unsigned char buffer[kBufferLength];
+ for (uintptr_t i = 0; i < kBufferLength; i++) {
+ buffer[i] = 42;
+ }
+ Utf8::Encode(input, reinterpret_cast<char*>(&buffer[0]), 10);
+ uintptr_t i;
+ for (i = 0; i < static_cast<uintptr_t>(Utf8::Length(input)); i++) {
+ EXPECT(buffer[i] > 127);
+ }
+ for (; i < kBufferLength; i++) {
+ EXPECT(buffer[i] == 42);
+ }
+}
+
TEST_CASE(Utf8Decode) {
// Examples from the Unicode specification, chapter 3
{
« no previous file with comments | « runtime/vm/unicode.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698