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

Side by Side Diff: src/objects.cc

Issue 8513010: Add pointer cache field to external string for access in generated code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 9 years, 1 month 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 947 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
948 ASSERT(memcmp(smart_chars.start(), 948 ASSERT(memcmp(smart_chars.start(),
949 resource->data(), 949 resource->data(),
950 resource->length() * sizeof(smart_chars[0])) == 0); 950 resource->length() * sizeof(smart_chars[0])) == 0);
951 } 951 }
952 #endif // DEBUG 952 #endif // DEBUG
953 Heap* heap = GetHeap(); 953 Heap* heap = GetHeap();
954 int size = this->Size(); // Byte size of the original string. 954 int size = this->Size(); // Byte size of the original string.
955 if (size < ExternalString::kSize) { 955 if (size < ExternalString::kSize) {
956 // The string is too small to fit an external String in its place. This can 956 // The string is too small to fit an external String in its place. This can
957 // only happen for zero length strings. 957 // only happen for strings with less than 3 characters.
958 return false; 958 return false;
959 } 959 }
960 ASSERT(size >= ExternalString::kSize); 960 ASSERT(size >= ExternalString::kSize);
961 bool is_ascii = this->IsAsciiRepresentation(); 961 bool is_ascii = this->IsAsciiRepresentation();
962 bool is_symbol = this->IsSymbol(); 962 bool is_symbol = this->IsSymbol();
963 int length = this->length(); 963 int length = this->length();
964 int hash_field = this->hash_field(); 964 int hash_field = this->hash_field();
965 965
966 // Morph the object to an external string by adjusting the map and 966 // Morph the object to an external string by adjusting the map and
967 // reinitializing the fields. 967 // reinitializing the fields.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 1001 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1002 ASSERT(memcmp(smart_chars.start(), 1002 ASSERT(memcmp(smart_chars.start(),
1003 resource->data(), 1003 resource->data(),
1004 resource->length() * sizeof(smart_chars[0])) == 0); 1004 resource->length() * sizeof(smart_chars[0])) == 0);
1005 } 1005 }
1006 #endif // DEBUG 1006 #endif // DEBUG
1007 Heap* heap = GetHeap(); 1007 Heap* heap = GetHeap();
1008 int size = this->Size(); // Byte size of the original string. 1008 int size = this->Size(); // Byte size of the original string.
1009 if (size < ExternalString::kSize) { 1009 if (size < ExternalString::kSize) {
1010 // The string is too small to fit an external String in its place. This can 1010 // The string is too small to fit an external String in its place. This can
1011 // only happen for zero length strings. 1011 // only happen for strings with less than 5 characters.
1012 return false; 1012 return false;
1013 } 1013 }
1014 ASSERT(size >= ExternalString::kSize); 1014 ASSERT(size >= ExternalString::kSize);
1015 bool is_symbol = this->IsSymbol(); 1015 bool is_symbol = this->IsSymbol();
1016 int length = this->length(); 1016 int length = this->length();
1017 int hash_field = this->hash_field(); 1017 int hash_field = this->hash_field();
1018 1018
1019 // Morph the object to an external string by adjusting the map and 1019 // Morph the object to an external string by adjusting the map and
1020 // reinitializing the fields. 1020 // reinitializing the fields.
1021 this->set_map(heap->external_ascii_string_map()); 1021 this->set_map(heap->external_ascii_string_map());
(...skipping 4761 matching lines...) Expand 10 before | Expand all | Expand 10 after
5783 string = slice->parent(); 5783 string = slice->parent();
5784 shape = StringShape(string); 5784 shape = StringShape(string);
5785 ASSERT(shape.representation_tag() != kConsStringTag && 5785 ASSERT(shape.representation_tag() != kConsStringTag &&
5786 shape.representation_tag() != kSlicedStringTag); 5786 shape.representation_tag() != kSlicedStringTag);
5787 } 5787 }
5788 if (shape.encoding_tag() == kAsciiStringTag) { 5788 if (shape.encoding_tag() == kAsciiStringTag) {
5789 const char* start; 5789 const char* start;
5790 if (shape.representation_tag() == kSeqStringTag) { 5790 if (shape.representation_tag() == kSeqStringTag) {
5791 start = SeqAsciiString::cast(string)->GetChars(); 5791 start = SeqAsciiString::cast(string)->GetChars();
5792 } else { 5792 } else {
5793 start = ExternalAsciiString::cast(string)->resource()->data(); 5793 start = ExternalAsciiString::cast(string)->GetChars();
5794 } 5794 }
5795 return FlatContent(Vector<const char>(start + offset, length)); 5795 return FlatContent(Vector<const char>(start + offset, length));
5796 } else { 5796 } else {
5797 ASSERT(shape.encoding_tag() == kTwoByteStringTag); 5797 ASSERT(shape.encoding_tag() == kTwoByteStringTag);
5798 const uc16* start; 5798 const uc16* start;
5799 if (shape.representation_tag() == kSeqStringTag) { 5799 if (shape.representation_tag() == kSeqStringTag) {
5800 start = SeqTwoByteString::cast(string)->GetChars(); 5800 start = SeqTwoByteString::cast(string)->GetChars();
5801 } else { 5801 } else {
5802 start = ExternalTwoByteString::cast(string)->resource()->data(); 5802 start = ExternalTwoByteString::cast(string)->GetChars();
5803 } 5803 }
5804 return FlatContent(Vector<const uc16>(start + offset, length)); 5804 return FlatContent(Vector<const uc16>(start + offset, length));
5805 } 5805 }
5806 } 5806 }
5807 5807
5808 5808
5809 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, 5809 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls,
5810 RobustnessFlag robust_flag, 5810 RobustnessFlag robust_flag,
5811 int offset, 5811 int offset,
5812 int length, 5812 int length,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
6027 max_chars > rbb->capacity ? rbb->capacity : max_chars); 6027 max_chars > rbb->capacity ? rbb->capacity : max_chars);
6028 *offset_ptr = offset + offset_correction; 6028 *offset_ptr = offset + offset_correction;
6029 return rbb->util_buffer; 6029 return rbb->util_buffer;
6030 } 6030 }
6031 } 6031 }
6032 } 6032 }
6033 6033
6034 6034
6035 uint16_t ExternalAsciiString::ExternalAsciiStringGet(int index) { 6035 uint16_t ExternalAsciiString::ExternalAsciiStringGet(int index) {
6036 ASSERT(index >= 0 && index < length()); 6036 ASSERT(index >= 0 && index < length());
6037 return resource()->data()[index]; 6037 return GetChars()[index];
6038 } 6038 }
6039 6039
6040 6040
6041 const unibrow::byte* ExternalAsciiString::ExternalAsciiStringReadBlock( 6041 const unibrow::byte* ExternalAsciiString::ExternalAsciiStringReadBlock(
6042 unsigned* remaining, 6042 unsigned* remaining,
6043 unsigned* offset_ptr, 6043 unsigned* offset_ptr,
6044 unsigned max_chars) { 6044 unsigned max_chars) {
6045 // Cast const char* to unibrow::byte* (signedness difference). 6045 // Cast const char* to unibrow::byte* (signedness difference).
6046 const unibrow::byte* b = 6046 const unibrow::byte* b =
6047 reinterpret_cast<const unibrow::byte*>(resource()->data()) + *offset_ptr; 6047 reinterpret_cast<const unibrow::byte*>(GetChars()) + *offset_ptr;
6048 *remaining = max_chars; 6048 *remaining = max_chars;
6049 *offset_ptr += max_chars; 6049 *offset_ptr += max_chars;
6050 return b; 6050 return b;
6051 } 6051 }
6052 6052
6053 6053
6054 const uc16* ExternalTwoByteString::ExternalTwoByteStringGetData( 6054 const uc16* ExternalTwoByteString::ExternalTwoByteStringGetData(
6055 unsigned start) { 6055 unsigned start) {
6056 return resource()->data() + start; 6056 return GetChars() + start;
Lasse Reichstein 2011/11/17 13:40:18 Functions like this are so small, it would be grea
6057 } 6057 }
6058 6058
6059 6059
6060 uint16_t ExternalTwoByteString::ExternalTwoByteStringGet(int index) { 6060 uint16_t ExternalTwoByteString::ExternalTwoByteStringGet(int index) {
6061 ASSERT(index >= 0 && index < length()); 6061 ASSERT(index >= 0 && index < length());
6062 return resource()->data()[index]; 6062 return GetChars()[index];
6063 } 6063 }
6064 6064
6065 6065
6066 void ExternalTwoByteString::ExternalTwoByteStringReadBlockIntoBuffer( 6066 void ExternalTwoByteString::ExternalTwoByteStringReadBlockIntoBuffer(
6067 ReadBlockBuffer* rbb, 6067 ReadBlockBuffer* rbb,
6068 unsigned* offset_ptr, 6068 unsigned* offset_ptr,
6069 unsigned max_chars) { 6069 unsigned max_chars) {
6070 unsigned chars_read = 0; 6070 unsigned chars_read = 0;
6071 unsigned offset = *offset_ptr; 6071 unsigned offset = *offset_ptr;
6072 const uint16_t* data = resource()->data(); 6072 const uint16_t* data = GetChars();
6073 while (chars_read < max_chars) { 6073 while (chars_read < max_chars) {
6074 uint16_t c = data[offset]; 6074 uint16_t c = data[offset];
6075 if (c <= kMaxAsciiCharCode) { 6075 if (c <= kMaxAsciiCharCode) {
6076 // Fast case for ASCII characters. Cursor is an input output argument. 6076 // Fast case for ASCII characters. Cursor is an input output argument.
6077 if (!unibrow::CharacterStream::EncodeAsciiCharacter(c, 6077 if (!unibrow::CharacterStream::EncodeAsciiCharacter(c,
6078 rbb->util_buffer, 6078 rbb->util_buffer,
6079 rbb->capacity, 6079 rbb->capacity,
6080 rbb->cursor)) 6080 rbb->cursor))
6081 break; 6081 break;
6082 } else { 6082 } else {
(...skipping 25 matching lines...) Expand all
6108 rbb->cursor += max_chars; 6108 rbb->cursor += max_chars;
6109 } 6109 }
6110 6110
6111 6111
6112 void ExternalAsciiString::ExternalAsciiStringReadBlockIntoBuffer( 6112 void ExternalAsciiString::ExternalAsciiStringReadBlockIntoBuffer(
6113 ReadBlockBuffer* rbb, 6113 ReadBlockBuffer* rbb,
6114 unsigned* offset_ptr, 6114 unsigned* offset_ptr,
6115 unsigned max_chars) { 6115 unsigned max_chars) {
6116 unsigned capacity = rbb->capacity - rbb->cursor; 6116 unsigned capacity = rbb->capacity - rbb->cursor;
6117 if (max_chars > capacity) max_chars = capacity; 6117 if (max_chars > capacity) max_chars = capacity;
6118 memcpy(rbb->util_buffer + rbb->cursor, 6118 memcpy(rbb->util_buffer + rbb->cursor, GetChars() + *offset_ptr, max_chars);
6119 resource()->data() + *offset_ptr,
6120 max_chars);
6121 rbb->remaining += max_chars; 6119 rbb->remaining += max_chars;
6122 *offset_ptr += max_chars; 6120 *offset_ptr += max_chars;
6123 rbb->cursor += max_chars; 6121 rbb->cursor += max_chars;
6124 } 6122 }
6125 6123
6126 6124
6127 // This method determines the type of string involved and then copies 6125 // This method determines the type of string involved and then copies
6128 // a whole chunk of characters into a buffer, or returns a pointer to a buffer 6126 // a whole chunk of characters into a buffer, or returns a pointer to a buffer
6129 // where they can be found. The pointer is not necessarily valid across a GC 6127 // where they can be found. The pointer is not necessarily valid across a GC
6130 // (see AsciiStringReadBlock). 6128 // (see AsciiStringReadBlock).
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
6552 int f, 6550 int f,
6553 int t) { 6551 int t) {
6554 String* source = src; 6552 String* source = src;
6555 int from = f; 6553 int from = f;
6556 int to = t; 6554 int to = t;
6557 while (true) { 6555 while (true) {
6558 ASSERT(0 <= from && from <= to && to <= source->length()); 6556 ASSERT(0 <= from && from <= to && to <= source->length());
6559 switch (StringShape(source).full_representation_tag()) { 6557 switch (StringShape(source).full_representation_tag()) {
6560 case kAsciiStringTag | kExternalStringTag: { 6558 case kAsciiStringTag | kExternalStringTag: {
6561 CopyChars(sink, 6559 CopyChars(sink,
6562 ExternalAsciiString::cast(source)->resource()->data() + from, 6560 ExternalAsciiString::cast(source)->GetChars() + from,
6563 to - from); 6561 to - from);
6564 return; 6562 return;
6565 } 6563 }
6566 case kTwoByteStringTag | kExternalStringTag: { 6564 case kTwoByteStringTag | kExternalStringTag: {
6567 const uc16* data = 6565 const uc16* data =
6568 ExternalTwoByteString::cast(source)->resource()->data(); 6566 ExternalTwoByteString::cast(source)->GetChars();
6569 CopyChars(sink, 6567 CopyChars(sink,
6570 data + from, 6568 data + from,
6571 to - from); 6569 to - from);
6572 return; 6570 return;
6573 } 6571 }
6574 case kAsciiStringTag | kSeqStringTag: { 6572 case kAsciiStringTag | kSeqStringTag: {
6575 CopyChars(sink, 6573 CopyChars(sink,
6576 SeqAsciiString::cast(source)->GetChars() + from, 6574 SeqAsciiString::cast(source)->GetChars() + from,
6577 to - from); 6575 to - from);
6578 return; 6576 return;
(...skipping 5960 matching lines...) Expand 10 before | Expand all | Expand 10 after
12539 if (break_point_objects()->IsUndefined()) return 0; 12537 if (break_point_objects()->IsUndefined()) return 0;
12540 // Single break point. 12538 // Single break point.
12541 if (!break_point_objects()->IsFixedArray()) return 1; 12539 if (!break_point_objects()->IsFixedArray()) return 1;
12542 // Multiple break points. 12540 // Multiple break points.
12543 return FixedArray::cast(break_point_objects())->length(); 12541 return FixedArray::cast(break_point_objects())->length();
12544 } 12542 }
12545 #endif // ENABLE_DEBUGGER_SUPPORT 12543 #endif // ENABLE_DEBUGGER_SUPPORT
12546 12544
12547 12545
12548 } } // namespace v8::internal 12546 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698