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

Side by Side Diff: src/objects.cc

Issue 8551006: Version 3.7.9. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years 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 | « src/objects.h ('k') | src/objects-inl.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 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 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 ScopedVector<uc16> smart_chars(this->length()); 946 ScopedVector<uc16> smart_chars(this->length());
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
957 // only happen for zero length strings.
958 return false; 956 return false;
959 } 957 }
960 ASSERT(size >= ExternalString::kSize); 958 ASSERT(size >= ExternalString::kSize);
961 bool is_ascii = this->IsAsciiRepresentation(); 959 bool is_ascii = this->IsAsciiRepresentation();
962 bool is_symbol = this->IsSymbol(); 960 bool is_symbol = this->IsSymbol();
963 int length = this->length(); 961 int length = this->length();
964 int hash_field = this->hash_field(); 962 int hash_field = this->hash_field();
965 963
966 // Morph the object to an external string by adjusting the map and 964 // Morph the object to an external string by adjusting the map and
967 // reinitializing the fields. 965 // reinitializing the fields.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 ScopedVector<char> smart_chars(this->length()); 998 ScopedVector<char> smart_chars(this->length());
1001 String::WriteToFlat(this, smart_chars.start(), 0, this->length()); 999 String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1002 ASSERT(memcmp(smart_chars.start(), 1000 ASSERT(memcmp(smart_chars.start(),
1003 resource->data(), 1001 resource->data(),
1004 resource->length() * sizeof(smart_chars[0])) == 0); 1002 resource->length() * sizeof(smart_chars[0])) == 0);
1005 } 1003 }
1006 #endif // DEBUG 1004 #endif // DEBUG
1007 Heap* heap = GetHeap(); 1005 Heap* heap = GetHeap();
1008 int size = this->Size(); // Byte size of the original string. 1006 int size = this->Size(); // Byte size of the original string.
1009 if (size < ExternalString::kSize) { 1007 if (size < ExternalString::kSize) {
1010 // The string is too small to fit an external String in its place. This can
1011 // only happen for zero length strings.
1012 return false; 1008 return false;
1013 } 1009 }
1014 ASSERT(size >= ExternalString::kSize); 1010 ASSERT(size >= ExternalString::kSize);
1015 bool is_symbol = this->IsSymbol(); 1011 bool is_symbol = this->IsSymbol();
1016 int length = this->length(); 1012 int length = this->length();
1017 int hash_field = this->hash_field(); 1013 int hash_field = this->hash_field();
1018 1014
1019 // Morph the object to an external string by adjusting the map and 1015 // Morph the object to an external string by adjusting the map and
1020 // reinitializing the fields. 1016 // reinitializing the fields.
1021 this->set_map(heap->external_ascii_string_map()); 1017 this->set_map(heap->external_ascii_string_map());
(...skipping 4761 matching lines...) Expand 10 before | Expand all | Expand 10 after
5783 string = slice->parent(); 5779 string = slice->parent();
5784 shape = StringShape(string); 5780 shape = StringShape(string);
5785 ASSERT(shape.representation_tag() != kConsStringTag && 5781 ASSERT(shape.representation_tag() != kConsStringTag &&
5786 shape.representation_tag() != kSlicedStringTag); 5782 shape.representation_tag() != kSlicedStringTag);
5787 } 5783 }
5788 if (shape.encoding_tag() == kAsciiStringTag) { 5784 if (shape.encoding_tag() == kAsciiStringTag) {
5789 const char* start; 5785 const char* start;
5790 if (shape.representation_tag() == kSeqStringTag) { 5786 if (shape.representation_tag() == kSeqStringTag) {
5791 start = SeqAsciiString::cast(string)->GetChars(); 5787 start = SeqAsciiString::cast(string)->GetChars();
5792 } else { 5788 } else {
5793 start = ExternalAsciiString::cast(string)->resource()->data(); 5789 start = ExternalAsciiString::cast(string)->GetChars();
5794 } 5790 }
5795 return FlatContent(Vector<const char>(start + offset, length)); 5791 return FlatContent(Vector<const char>(start + offset, length));
5796 } else { 5792 } else {
5797 ASSERT(shape.encoding_tag() == kTwoByteStringTag); 5793 ASSERT(shape.encoding_tag() == kTwoByteStringTag);
5798 const uc16* start; 5794 const uc16* start;
5799 if (shape.representation_tag() == kSeqStringTag) { 5795 if (shape.representation_tag() == kSeqStringTag) {
5800 start = SeqTwoByteString::cast(string)->GetChars(); 5796 start = SeqTwoByteString::cast(string)->GetChars();
5801 } else { 5797 } else {
5802 start = ExternalTwoByteString::cast(string)->resource()->data(); 5798 start = ExternalTwoByteString::cast(string)->GetChars();
5803 } 5799 }
5804 return FlatContent(Vector<const uc16>(start + offset, length)); 5800 return FlatContent(Vector<const uc16>(start + offset, length));
5805 } 5801 }
5806 } 5802 }
5807 5803
5808 5804
5809 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, 5805 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls,
5810 RobustnessFlag robust_flag, 5806 RobustnessFlag robust_flag,
5811 int offset, 5807 int offset,
5812 int length, 5808 int length,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
6025 rbb, 6021 rbb,
6026 &offset, 6022 &offset,
6027 max_chars > rbb->capacity ? rbb->capacity : max_chars); 6023 max_chars > rbb->capacity ? rbb->capacity : max_chars);
6028 *offset_ptr = offset + offset_correction; 6024 *offset_ptr = offset + offset_correction;
6029 return rbb->util_buffer; 6025 return rbb->util_buffer;
6030 } 6026 }
6031 } 6027 }
6032 } 6028 }
6033 6029
6034 6030
6035 uint16_t ExternalAsciiString::ExternalAsciiStringGet(int index) {
6036 ASSERT(index >= 0 && index < length());
6037 return resource()->data()[index];
6038 }
6039
6040
6041 const unibrow::byte* ExternalAsciiString::ExternalAsciiStringReadBlock( 6031 const unibrow::byte* ExternalAsciiString::ExternalAsciiStringReadBlock(
6042 unsigned* remaining, 6032 unsigned* remaining,
6043 unsigned* offset_ptr, 6033 unsigned* offset_ptr,
6044 unsigned max_chars) { 6034 unsigned max_chars) {
6045 // Cast const char* to unibrow::byte* (signedness difference). 6035 // Cast const char* to unibrow::byte* (signedness difference).
6046 const unibrow::byte* b = 6036 const unibrow::byte* b =
6047 reinterpret_cast<const unibrow::byte*>(resource()->data()) + *offset_ptr; 6037 reinterpret_cast<const unibrow::byte*>(GetChars()) + *offset_ptr;
6048 *remaining = max_chars; 6038 *remaining = max_chars;
6049 *offset_ptr += max_chars; 6039 *offset_ptr += max_chars;
6050 return b; 6040 return b;
6051 } 6041 }
6052 6042
6053 6043
6054 const uc16* ExternalTwoByteString::ExternalTwoByteStringGetData(
6055 unsigned start) {
6056 return resource()->data() + start;
6057 }
6058
6059
6060 uint16_t ExternalTwoByteString::ExternalTwoByteStringGet(int index) {
6061 ASSERT(index >= 0 && index < length());
6062 return resource()->data()[index];
6063 }
6064
6065
6066 void ExternalTwoByteString::ExternalTwoByteStringReadBlockIntoBuffer( 6044 void ExternalTwoByteString::ExternalTwoByteStringReadBlockIntoBuffer(
6067 ReadBlockBuffer* rbb, 6045 ReadBlockBuffer* rbb,
6068 unsigned* offset_ptr, 6046 unsigned* offset_ptr,
6069 unsigned max_chars) { 6047 unsigned max_chars) {
6070 unsigned chars_read = 0; 6048 unsigned chars_read = 0;
6071 unsigned offset = *offset_ptr; 6049 unsigned offset = *offset_ptr;
6072 const uint16_t* data = resource()->data(); 6050 const uint16_t* data = GetChars();
6073 while (chars_read < max_chars) { 6051 while (chars_read < max_chars) {
6074 uint16_t c = data[offset]; 6052 uint16_t c = data[offset];
6075 if (c <= kMaxAsciiCharCode) { 6053 if (c <= kMaxAsciiCharCode) {
6076 // Fast case for ASCII characters. Cursor is an input output argument. 6054 // Fast case for ASCII characters. Cursor is an input output argument.
6077 if (!unibrow::CharacterStream::EncodeAsciiCharacter(c, 6055 if (!unibrow::CharacterStream::EncodeAsciiCharacter(c,
6078 rbb->util_buffer, 6056 rbb->util_buffer,
6079 rbb->capacity, 6057 rbb->capacity,
6080 rbb->cursor)) 6058 rbb->cursor))
6081 break; 6059 break;
6082 } else { 6060 } else {
(...skipping 25 matching lines...) Expand all
6108 rbb->cursor += max_chars; 6086 rbb->cursor += max_chars;
6109 } 6087 }
6110 6088
6111 6089
6112 void ExternalAsciiString::ExternalAsciiStringReadBlockIntoBuffer( 6090 void ExternalAsciiString::ExternalAsciiStringReadBlockIntoBuffer(
6113 ReadBlockBuffer* rbb, 6091 ReadBlockBuffer* rbb,
6114 unsigned* offset_ptr, 6092 unsigned* offset_ptr,
6115 unsigned max_chars) { 6093 unsigned max_chars) {
6116 unsigned capacity = rbb->capacity - rbb->cursor; 6094 unsigned capacity = rbb->capacity - rbb->cursor;
6117 if (max_chars > capacity) max_chars = capacity; 6095 if (max_chars > capacity) max_chars = capacity;
6118 memcpy(rbb->util_buffer + rbb->cursor, 6096 memcpy(rbb->util_buffer + rbb->cursor, GetChars() + *offset_ptr, max_chars);
6119 resource()->data() + *offset_ptr,
6120 max_chars);
6121 rbb->remaining += max_chars; 6097 rbb->remaining += max_chars;
6122 *offset_ptr += max_chars; 6098 *offset_ptr += max_chars;
6123 rbb->cursor += max_chars; 6099 rbb->cursor += max_chars;
6124 } 6100 }
6125 6101
6126 6102
6127 // This method determines the type of string involved and then copies 6103 // 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 6104 // 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 6105 // where they can be found. The pointer is not necessarily valid across a GC
6130 // (see AsciiStringReadBlock). 6106 // (see AsciiStringReadBlock).
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
6552 int f, 6528 int f,
6553 int t) { 6529 int t) {
6554 String* source = src; 6530 String* source = src;
6555 int from = f; 6531 int from = f;
6556 int to = t; 6532 int to = t;
6557 while (true) { 6533 while (true) {
6558 ASSERT(0 <= from && from <= to && to <= source->length()); 6534 ASSERT(0 <= from && from <= to && to <= source->length());
6559 switch (StringShape(source).full_representation_tag()) { 6535 switch (StringShape(source).full_representation_tag()) {
6560 case kAsciiStringTag | kExternalStringTag: { 6536 case kAsciiStringTag | kExternalStringTag: {
6561 CopyChars(sink, 6537 CopyChars(sink,
6562 ExternalAsciiString::cast(source)->resource()->data() + from, 6538 ExternalAsciiString::cast(source)->GetChars() + from,
6563 to - from); 6539 to - from);
6564 return; 6540 return;
6565 } 6541 }
6566 case kTwoByteStringTag | kExternalStringTag: { 6542 case kTwoByteStringTag | kExternalStringTag: {
6567 const uc16* data = 6543 const uc16* data =
6568 ExternalTwoByteString::cast(source)->resource()->data(); 6544 ExternalTwoByteString::cast(source)->GetChars();
6569 CopyChars(sink, 6545 CopyChars(sink,
6570 data + from, 6546 data + from,
6571 to - from); 6547 to - from);
6572 return; 6548 return;
6573 } 6549 }
6574 case kAsciiStringTag | kSeqStringTag: { 6550 case kAsciiStringTag | kSeqStringTag: {
6575 CopyChars(sink, 6551 CopyChars(sink,
6576 SeqAsciiString::cast(source)->GetChars() + from, 6552 SeqAsciiString::cast(source)->GetChars() + from,
6577 to - from); 6553 to - from);
6578 return; 6554 return;
(...skipping 3400 matching lines...) Expand 10 before | Expand all | Expand 10 after
9979 return NumberOfLocalProperties(static_cast<PropertyAttributes>(DONT_ENUM)); 9955 return NumberOfLocalProperties(static_cast<PropertyAttributes>(DONT_ENUM));
9980 } 9956 }
9981 9957
9982 9958
9983 void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) { 9959 void FixedArray::SwapPairs(FixedArray* numbers, int i, int j) {
9984 Object* temp = get(i); 9960 Object* temp = get(i);
9985 set(i, get(j)); 9961 set(i, get(j));
9986 set(j, temp); 9962 set(j, temp);
9987 if (this != numbers) { 9963 if (this != numbers) {
9988 temp = numbers->get(i); 9964 temp = numbers->get(i);
9989 numbers->set(i, numbers->get(j)); 9965 numbers->set(i, Smi::cast(numbers->get(j)));
9990 numbers->set(j, temp); 9966 numbers->set(j, Smi::cast(temp));
9991 } 9967 }
9992 } 9968 }
9993 9969
9994 9970
9995 static void InsertionSortPairs(FixedArray* content, 9971 static void InsertionSortPairs(FixedArray* content,
9996 FixedArray* numbers, 9972 FixedArray* numbers,
9997 int len) { 9973 int len) {
9998 for (int i = 1; i < len; i++) { 9974 for (int i = 1; i < len; i++) {
9999 int j = i; 9975 int j = i;
10000 while (j > 0 && 9976 while (j > 0 &&
(...skipping 2538 matching lines...) Expand 10 before | Expand all | Expand 10 after
12539 if (break_point_objects()->IsUndefined()) return 0; 12515 if (break_point_objects()->IsUndefined()) return 0;
12540 // Single break point. 12516 // Single break point.
12541 if (!break_point_objects()->IsFixedArray()) return 1; 12517 if (!break_point_objects()->IsFixedArray()) return 1;
12542 // Multiple break points. 12518 // Multiple break points.
12543 return FixedArray::cast(break_point_objects())->length(); 12519 return FixedArray::cast(break_point_objects())->length();
12544 } 12520 }
12545 #endif // ENABLE_DEBUGGER_SUPPORT 12521 #endif // ENABLE_DEBUGGER_SUPPORT
12546 12522
12547 12523
12548 } } // namespace v8::internal 12524 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698