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

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

Issue 8339002: Add a const qualifier to string handles which are not reassigned. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « 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 // 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 5242 matching lines...) Expand 10 before | Expand all | Expand 10 after
5253 5253
5254 // This string is a symbol if we found a matching entry. 5254 // This string is a symbol if we found a matching entry.
5255 return !symbol.IsNull(); 5255 return !symbol.IsNull();
5256 } 5256 }
5257 5257
5258 5258
5259 RawString* String::New(const char* str, Heap::Space space) { 5259 RawString* String::New(const char* str, Heap::Space space) {
5260 intptr_t width = 0; 5260 intptr_t width = 0;
5261 intptr_t len = Utf8::CodePointCount(str, &width); 5261 intptr_t len = Utf8::CodePointCount(str, &width);
5262 if (width == 1) { 5262 if (width == 1) {
5263 OneByteString& onestr 5263 const OneByteString& onestr
5264 = OneByteString::Handle(OneByteString::New(len, space)); 5264 = OneByteString::Handle(OneByteString::New(len, space));
5265 if (len > 0) { 5265 if (len > 0) {
5266 NoGCScope no_gc; 5266 NoGCScope no_gc;
5267 Utf8::Decode(str, onestr.CharAddr(0), len); 5267 Utf8::Decode(str, onestr.CharAddr(0), len);
5268 } 5268 }
5269 return onestr.raw(); 5269 return onestr.raw();
5270 } else if (width == 2) { 5270 } else if (width == 2) {
5271 TwoByteString& twostr = 5271 const TwoByteString& twostr =
5272 TwoByteString::Handle(TwoByteString::New(len, space)); 5272 TwoByteString::Handle(TwoByteString::New(len, space));
5273 NoGCScope no_gc; 5273 NoGCScope no_gc;
5274 Utf8::Decode(str, twostr.CharAddr(0), len); 5274 Utf8::Decode(str, twostr.CharAddr(0), len);
5275 return twostr.raw(); 5275 return twostr.raw();
5276 } 5276 }
5277 ASSERT(width == 4); 5277 ASSERT(width == 4);
5278 FourByteString& fourstr = 5278 const FourByteString& fourstr =
5279 FourByteString::Handle(FourByteString::New(len, space)); 5279 FourByteString::Handle(FourByteString::New(len, space));
5280 NoGCScope no_gc; 5280 NoGCScope no_gc;
5281 Utf8::Decode(str, fourstr.CharAddr(0), len); 5281 Utf8::Decode(str, fourstr.CharAddr(0), len);
5282 return fourstr.raw(); 5282 return fourstr.raw();
5283 } 5283 }
5284 5284
5285 5285
5286 RawString* String::New(const uint8_t* characters, 5286 RawString* String::New(const uint8_t* characters,
5287 intptr_t len, 5287 intptr_t len,
5288 Heap::Space space) { 5288 Heap::Space space) {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
5737 result.SetLength(len); 5737 result.SetLength(len);
5738 result.SetHash(0); 5738 result.SetHash(0);
5739 } 5739 }
5740 return result.raw(); 5740 return result.raw();
5741 } 5741 }
5742 5742
5743 5743
5744 RawOneByteString* OneByteString::New(const uint8_t* characters, 5744 RawOneByteString* OneByteString::New(const uint8_t* characters,
5745 intptr_t len, 5745 intptr_t len,
5746 Heap::Space space) { 5746 Heap::Space space) {
5747 OneByteString& result = OneByteString::Handle(OneByteString::New(len, space)); 5747 const OneByteString& result =
5748 OneByteString::Handle(OneByteString::New(len, space));
5748 String::Copy(result, 0, characters, len); 5749 String::Copy(result, 0, characters, len);
5749 return result.raw(); 5750 return result.raw();
5750 } 5751 }
5751 5752
5752 5753
5753 RawOneByteString* OneByteString::New(const uint16_t* characters, 5754 RawOneByteString* OneByteString::New(const uint16_t* characters,
5754 intptr_t len, 5755 intptr_t len,
5755 Heap::Space space) { 5756 Heap::Space space) {
5756 OneByteString& result = OneByteString::Handle(OneByteString::New(len, space)); 5757 const OneByteString& result =
5758 OneByteString::Handle(OneByteString::New(len, space));
5757 String::Copy(result, 0, characters, len); 5759 String::Copy(result, 0, characters, len);
5758 return result.raw(); 5760 return result.raw();
5759 } 5761 }
5760 5762
5761 5763
5762 RawOneByteString* OneByteString::New(const uint32_t* characters, 5764 RawOneByteString* OneByteString::New(const uint32_t* characters,
5763 intptr_t len, 5765 intptr_t len,
5764 Heap::Space space) { 5766 Heap::Space space) {
5765 OneByteString& result = OneByteString::Handle(OneByteString::New(len, space)); 5767 const OneByteString& result =
5768 OneByteString::Handle(OneByteString::New(len, space));
5766 String::Copy(result, 0, characters, len); 5769 String::Copy(result, 0, characters, len);
5767 return result.raw(); 5770 return result.raw();
5768 } 5771 }
5769 5772
5770 5773
5771 RawOneByteString* OneByteString::New(const OneByteString& str, 5774 RawOneByteString* OneByteString::New(const OneByteString& str,
5772 Heap::Space space) { 5775 Heap::Space space) {
5773 intptr_t len = str.Length(); 5776 intptr_t len = str.Length();
5774 OneByteString& result = OneByteString::Handle(OneByteString::New(len, space)); 5777 const OneByteString& result =
5778 OneByteString::Handle(OneByteString::New(len, space));
5775 String::Copy(result, 0, str, 0, len); 5779 String::Copy(result, 0, str, 0, len);
5776 return result.raw(); 5780 return result.raw();
5777 } 5781 }
5778 5782
5779 5783
5780 RawOneByteString* OneByteString::Concat(const String& str1, 5784 RawOneByteString* OneByteString::Concat(const String& str1,
5781 const String& str2, 5785 const String& str2,
5782 Heap::Space space) { 5786 Heap::Space space) {
5783 intptr_t len1 = str1.Length(); 5787 intptr_t len1 = str1.Length();
5784 intptr_t len2 = str2.Length(); 5788 intptr_t len2 = str2.Length();
5785 intptr_t len = len1 + len2; 5789 intptr_t len = len1 + len2;
5786 OneByteString& result = OneByteString::Handle(OneByteString::New(len, space)); 5790 const OneByteString& result =
5791 OneByteString::Handle(OneByteString::New(len, space));
5787 String::Copy(result, 0, str1, 0, len1); 5792 String::Copy(result, 0, str1, 0, len1);
5788 String::Copy(result, len1, str2, 0, len2); 5793 String::Copy(result, len1, str2, 0, len2);
5789 return result.raw(); 5794 return result.raw();
5790 } 5795 }
5791 5796
5792 5797
5793 RawOneByteString* OneByteString::ConcatAll(const Array& strings, 5798 RawOneByteString* OneByteString::ConcatAll(const Array& strings,
5794 intptr_t len, 5799 intptr_t len,
5795 Heap::Space space) { 5800 Heap::Space space) {
5796 OneByteString& result = OneByteString::Handle(OneByteString::New(len, space)); 5801 const OneByteString& result =
5802 OneByteString::Handle(OneByteString::New(len, space));
5797 OneByteString& str = OneByteString::Handle(); 5803 OneByteString& str = OneByteString::Handle();
5798 intptr_t strings_len = strings.Length(); 5804 intptr_t strings_len = strings.Length();
5799 intptr_t pos = 0; 5805 intptr_t pos = 0;
5800 for (intptr_t i = 0; i < strings_len; i++) { 5806 for (intptr_t i = 0; i < strings_len; i++) {
5801 str ^= strings.At(i); 5807 str ^= strings.At(i);
5802 intptr_t str_len = str.Length(); 5808 intptr_t str_len = str.Length();
5803 String::Copy(result, pos, str, 0, str_len); 5809 String::Copy(result, pos, str, 0, str_len);
5804 pos += str_len; 5810 pos += str_len;
5805 } 5811 }
5806 return result.raw(); 5812 return result.raw();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5844 result.SetLength(len); 5850 result.SetLength(len);
5845 result.SetHash(0); 5851 result.SetHash(0);
5846 } 5852 }
5847 return result.raw(); 5853 return result.raw();
5848 } 5854 }
5849 5855
5850 5856
5851 RawTwoByteString* TwoByteString::New(const uint16_t* characters, 5857 RawTwoByteString* TwoByteString::New(const uint16_t* characters,
5852 intptr_t len, 5858 intptr_t len,
5853 Heap::Space space) { 5859 Heap::Space space) {
5854 TwoByteString& result = TwoByteString::Handle(TwoByteString::New(len, space)); 5860 const TwoByteString& result =
5861 TwoByteString::Handle(TwoByteString::New(len, space));
5855 String::Copy(result, 0, characters, len); 5862 String::Copy(result, 0, characters, len);
5856 return result.raw(); 5863 return result.raw();
5857 } 5864 }
5858 5865
5859 5866
5860 RawTwoByteString* TwoByteString::New(const uint32_t* characters, 5867 RawTwoByteString* TwoByteString::New(const uint32_t* characters,
5861 intptr_t len, 5868 intptr_t len,
5862 Heap::Space space) { 5869 Heap::Space space) {
5863 TwoByteString& result = TwoByteString::Handle(TwoByteString::New(len, space)); 5870 const TwoByteString& result =
5871 TwoByteString::Handle(TwoByteString::New(len, space));
5864 String::Copy(result, 0, characters, len); 5872 String::Copy(result, 0, characters, len);
5865 return result.raw(); 5873 return result.raw();
5866 } 5874 }
5867 5875
5868 5876
5869 RawTwoByteString* TwoByteString::New(const TwoByteString& str, 5877 RawTwoByteString* TwoByteString::New(const TwoByteString& str,
5870 Heap::Space space) { 5878 Heap::Space space) {
5871 intptr_t len = str.Length(); 5879 intptr_t len = str.Length();
5872 TwoByteString& result = TwoByteString::Handle(TwoByteString::New(len, space)); 5880 const TwoByteString& result =
5881 TwoByteString::Handle(TwoByteString::New(len, space));
5873 String::Copy(result, 0, str, 0, len); 5882 String::Copy(result, 0, str, 0, len);
5874 return result.raw(); 5883 return result.raw();
5875 } 5884 }
5876 5885
5877 5886
5878 RawTwoByteString* TwoByteString::Concat(const String& str1, 5887 RawTwoByteString* TwoByteString::Concat(const String& str1,
5879 const String& str2, 5888 const String& str2,
5880 Heap::Space space) { 5889 Heap::Space space) {
5881 TwoByteString& result = TwoByteString::Handle();
5882 intptr_t len1 = str1.Length(); 5890 intptr_t len1 = str1.Length();
5883 intptr_t len2 = str2.Length(); 5891 intptr_t len2 = str2.Length();
5884 intptr_t len = len1 + len2; 5892 intptr_t len = len1 + len2;
5885 result ^= TwoByteString::New(len, space); 5893 const TwoByteString& result =
5894 TwoByteString::Handle(TwoByteString::New(len, space));
5886 String::Copy(result, 0, str1, 0, len1); 5895 String::Copy(result, 0, str1, 0, len1);
5887 String::Copy(result, len1, str2, 0, len2); 5896 String::Copy(result, len1, str2, 0, len2);
5888 return result.raw(); 5897 return result.raw();
5889 } 5898 }
5890 5899
5891 5900
5892 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, 5901 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings,
5893 intptr_t len, 5902 intptr_t len,
5894 Heap::Space space) { 5903 Heap::Space space) {
5895 TwoByteString& result = TwoByteString::Handle(TwoByteString::New(len, space)); 5904 const TwoByteString& result =
5905 TwoByteString::Handle(TwoByteString::New(len, space));
5896 String& str = String::Handle(); 5906 String& str = String::Handle();
5897 intptr_t strings_len = strings.Length(); 5907 intptr_t strings_len = strings.Length();
5898 intptr_t pos = 0; 5908 intptr_t pos = 0;
5899 for (intptr_t i = 0; i < strings_len; i++) { 5909 for (intptr_t i = 0; i < strings_len; i++) {
5900 str ^= strings.At(i); 5910 str ^= strings.At(i);
5901 intptr_t str_len = str.Length(); 5911 intptr_t str_len = str.Length();
5902 String::Copy(result, pos, str, 0, str_len); 5912 String::Copy(result, pos, str, 0, str_len);
5903 pos += str_len; 5913 pos += str_len;
5904 } 5914 }
5905 return result.raw(); 5915 return result.raw();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5944 result.SetLength(len); 5954 result.SetLength(len);
5945 result.SetHash(0); 5955 result.SetHash(0);
5946 } 5956 }
5947 return result.raw(); 5957 return result.raw();
5948 } 5958 }
5949 5959
5950 5960
5951 RawFourByteString* FourByteString::New(const uint32_t* characters, 5961 RawFourByteString* FourByteString::New(const uint32_t* characters,
5952 intptr_t len, 5962 intptr_t len,
5953 Heap::Space space) { 5963 Heap::Space space) {
5954 FourByteString& result = 5964 const FourByteString& result =
5955 FourByteString::Handle(FourByteString::New(len, space)); 5965 FourByteString::Handle(FourByteString::New(len, space));
5956 String::Copy(result, 0, characters, len); 5966 String::Copy(result, 0, characters, len);
5957 return result.raw(); 5967 return result.raw();
5958 } 5968 }
5959 5969
5960 5970
5961 RawFourByteString* FourByteString::New(const FourByteString& str, 5971 RawFourByteString* FourByteString::New(const FourByteString& str,
5962 Heap::Space space) { 5972 Heap::Space space) {
5963 return FourByteString::New(str.CharAddr(0), str.Length(), space); 5973 return FourByteString::New(str.CharAddr(0), str.Length(), space);
5964 } 5974 }
5965 5975
5966 5976
5967 RawFourByteString* FourByteString::Concat(const String& str1, 5977 RawFourByteString* FourByteString::Concat(const String& str1,
5968 const String& str2, 5978 const String& str2,
5969 Heap::Space space) { 5979 Heap::Space space) {
5970 intptr_t len1 = str1.Length(); 5980 intptr_t len1 = str1.Length();
5971 intptr_t len2 = str2.Length(); 5981 intptr_t len2 = str2.Length();
5972 intptr_t len = len1 + len2; 5982 intptr_t len = len1 + len2;
5973 FourByteString& result = 5983 const FourByteString& result =
5974 FourByteString::Handle(FourByteString::New(len, space)); 5984 FourByteString::Handle(FourByteString::New(len, space));
5975 String::Copy(result, 0, str1, 0, len1); 5985 String::Copy(result, 0, str1, 0, len1);
5976 String::Copy(result, len1, str2, 0, len2); 5986 String::Copy(result, len1, str2, 0, len2);
5977 return result.raw(); 5987 return result.raw();
5978 } 5988 }
5979 5989
5980 5990
5981 RawFourByteString* FourByteString::ConcatAll(const Array& strings, 5991 RawFourByteString* FourByteString::ConcatAll(const Array& strings,
5982 intptr_t len, 5992 intptr_t len,
5983 Heap::Space space) { 5993 Heap::Space space) {
5984 FourByteString& result = 5994 const FourByteString& result =
5985 FourByteString::Handle(FourByteString::New(len, space)); 5995 FourByteString::Handle(FourByteString::New(len, space));
5986 String& str = String::Handle(); 5996 String& str = String::Handle();
5987 { 5997 {
5988 intptr_t strings_len = strings.Length(); 5998 intptr_t strings_len = strings.Length();
5989 intptr_t pos = 0; 5999 intptr_t pos = 0;
5990 for (intptr_t i = 0; i < strings_len; i++) { 6000 for (intptr_t i = 0; i < strings_len; i++) {
5991 str ^= strings.At(i); 6001 str ^= strings.At(i);
5992 intptr_t str_len = str.Length(); 6002 intptr_t str_len = str.Length();
5993 String::Copy(result, pos, str, 0, str_len); 6003 String::Copy(result, pos, str, 0, str_len);
5994 pos += str_len; 6004 pos += str_len;
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
6445 const String& str = String::Handle(pattern()); 6455 const String& str = String::Handle(pattern());
6446 const char* format = "JSRegExp: pattern=%s flags=%s"; 6456 const char* format = "JSRegExp: pattern=%s flags=%s";
6447 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 6457 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6448 char* chars = reinterpret_cast<char*>( 6458 char* chars = reinterpret_cast<char*>(
6449 Isolate::Current()->current_zone()->Allocate(len + 1)); 6459 Isolate::Current()->current_zone()->Allocate(len + 1));
6450 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 6460 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6451 return chars; 6461 return chars;
6452 } 6462 }
6453 6463
6454 } // namespace dart 6464 } // namespace dart
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