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

Side by Side Diff: runtime/vm/object.cc

Issue 8346014: Use the narrowest character width possible for substrings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improved changelog message. Created 9 years, 2 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 | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 5799 matching lines...) Expand 10 before | Expand all | Expand 10 after
5810 for (intptr_t i = 0; i < strings_len; i++) { 5810 for (intptr_t i = 0; i < strings_len; i++) {
5811 str ^= strings.At(i); 5811 str ^= strings.At(i);
5812 intptr_t str_len = str.Length(); 5812 intptr_t str_len = str.Length();
5813 String::Copy(result, pos, str, 0, str_len); 5813 String::Copy(result, pos, str, 0, str_len);
5814 pos += str_len; 5814 pos += str_len;
5815 } 5815 }
5816 return result.raw(); 5816 return result.raw();
5817 } 5817 }
5818 5818
5819 5819
5820 RawOneByteString* OneByteString::SubString(const OneByteString& str, 5820 RawString* OneByteString::SubString(const OneByteString& str,
5821 intptr_t begin_index, 5821 intptr_t begin_index,
5822 intptr_t length, 5822 intptr_t length,
5823 Heap::Space space) { 5823 Heap::Space space) {
5824 ASSERT(!str.IsNull()); 5824 ASSERT(!str.IsNull());
5825 ASSERT(begin_index < str.Length()); 5825 ASSERT(begin_index < str.Length());
5826 OneByteString& result = OneByteString::Handle(); 5826 OneByteString& result = OneByteString::Handle();
5827 if (length <= (str.Length() - begin_index)) { 5827 if (length <= (str.Length() - begin_index)) {
5828 result ^= OneByteString::New(length, space); 5828 result ^= OneByteString::New(length, space);
5829 String::Copy(result, 0, str, begin_index, length); 5829 String::Copy(result, 0, str, begin_index, length);
5830 } 5830 }
5831 // TODO(5418937): return a non-null object on error. 5831 // TODO(5418937): return a non-null object on error.
5832 return result.raw(); 5832 return result.raw();
5833 } 5833 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5913 for (intptr_t i = 0; i < strings_len; i++) { 5913 for (intptr_t i = 0; i < strings_len; i++) {
5914 str ^= strings.At(i); 5914 str ^= strings.At(i);
5915 intptr_t str_len = str.Length(); 5915 intptr_t str_len = str.Length();
5916 String::Copy(result, pos, str, 0, str_len); 5916 String::Copy(result, pos, str, 0, str_len);
5917 pos += str_len; 5917 pos += str_len;
5918 } 5918 }
5919 return result.raw(); 5919 return result.raw();
5920 } 5920 }
5921 5921
5922 5922
5923 RawTwoByteString* TwoByteString::SubString(const TwoByteString& str, 5923 RawString* TwoByteString::SubString(const TwoByteString& str,
5924 intptr_t begin_index, 5924 intptr_t begin_index,
5925 intptr_t length, 5925 intptr_t length,
5926 Heap::Space space) { 5926 Heap::Space space) {
5927 ASSERT(!str.IsNull()); 5927 ASSERT(!str.IsNull());
5928 ASSERT(begin_index < str.Length()); 5928 ASSERT(begin_index < str.Length());
5929 TwoByteString& result = TwoByteString::Handle(); 5929 String& result = String::Handle();
5930 if (length <= (str.Length() - begin_index)) { 5930 if (length <= (str.Length() - begin_index)) {
5931 result ^= TwoByteString::New(length, space); 5931 bool is_one_byte_string = true;
5932 for (intptr_t i = begin_index; i < begin_index + length; ++i) {
5933 if (str.CharAt(i) > 0xFF) {
5934 is_one_byte_string = false;
5935 break;
5936 }
5937 }
5938 if (is_one_byte_string) {
5939 result ^= OneByteString::New(length, space);
5940 } else {
5941 result ^= TwoByteString::New(length, space);
5942 }
5932 String::Copy(result, 0, str, begin_index, length); 5943 String::Copy(result, 0, str, begin_index, length);
5933 } 5944 }
5934 // TODO(5418937): return a non-null object on error. 5945 // TODO(5418937): return a non-null object on error.
5935 return result.raw(); 5946 return result.raw();
5936 } 5947 }
5937 5948
5938 5949
5939 const char* TwoByteString::ToCString() const { 5950 const char* TwoByteString::ToCString() const {
5940 return String::ToCString(); 5951 return String::ToCString();
5941 } 5952 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
6005 str ^= strings.At(i); 6016 str ^= strings.At(i);
6006 intptr_t str_len = str.Length(); 6017 intptr_t str_len = str.Length();
6007 String::Copy(result, pos, str, 0, str_len); 6018 String::Copy(result, pos, str, 0, str_len);
6008 pos += str_len; 6019 pos += str_len;
6009 } 6020 }
6010 } 6021 }
6011 return result.raw(); 6022 return result.raw();
6012 } 6023 }
6013 6024
6014 6025
6015 RawFourByteString* FourByteString::SubString(const FourByteString& str, 6026 RawString* FourByteString::SubString(const FourByteString& str,
6016 intptr_t begin_index, 6027 intptr_t begin_index,
6017 intptr_t length, 6028 intptr_t length,
6018 Heap::Space space) { 6029 Heap::Space space) {
6019 ASSERT(!str.IsNull()); 6030 ASSERT(!str.IsNull());
6020 ASSERT(begin_index < str.Length()); 6031 ASSERT(begin_index < str.Length());
6021 FourByteString& result = FourByteString::Handle(); 6032 String& result = String::Handle();
6022 if (length <= (str.Length() - begin_index)) { 6033 if (length <= (str.Length() - begin_index)) {
6023 result ^= FourByteString::New(length, space); 6034 bool is_one_byte_string = true;
6035 bool is_two_byte_string = true;
6036 for (intptr_t i = begin_index; i < begin_index + length; ++i) {
6037 if (str.CharAt(i) > 0xFFFF) {
6038 is_one_byte_string = false;
6039 is_two_byte_string = false;
6040 break;
6041 } else if (str.CharAt(i) > 0xFF) {
6042 is_one_byte_string = false;
6043 }
6044 }
6045 if (is_one_byte_string) {
6046 result ^= OneByteString::New(length, space);
6047 } else if (is_two_byte_string) {
6048 result ^= TwoByteString::New(length, space);
6049 } else {
6050 result ^= FourByteString::New(length, space);
6051 }
6024 String::Copy(result, 0, str, begin_index, length); 6052 String::Copy(result, 0, str, begin_index, length);
6025 } 6053 }
6026 // TODO(5418937): return a non-null object on error. 6054 // TODO(5418937): return a non-null object on error.
6027 return result.raw(); 6055 return result.raw();
6028 } 6056 }
6029 6057
6030 6058
6031 const char* FourByteString::ToCString() const { 6059 const char* FourByteString::ToCString() const {
6032 return String::ToCString(); 6060 return String::ToCString();
6033 } 6061 }
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
6459 const String& str = String::Handle(pattern()); 6487 const String& str = String::Handle(pattern());
6460 const char* format = "JSRegExp: pattern=%s flags=%s"; 6488 const char* format = "JSRegExp: pattern=%s flags=%s";
6461 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 6489 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6462 char* chars = reinterpret_cast<char*>( 6490 char* chars = reinterpret_cast<char*>(
6463 Isolate::Current()->current_zone()->Allocate(len + 1)); 6491 Isolate::Current()->current_zone()->Allocate(len + 1));
6464 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 6492 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6465 return chars; 6493 return chars;
6466 } 6494 }
6467 6495
6468 } // namespace dart 6496 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698