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

Side by Side Diff: src/objects.cc

Issue 9181: Push string shape fixes to trunk (version 0.4.3.1). (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 12 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
« no previous file with comments | « src/objects.h ('k') | src/parser.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 3699 matching lines...) Expand 10 before | Expand all | Expand 10 after
3710 } else { 3710 } else {
3711 return string->Get(shape, index); 3711 return string->Get(shape, index);
3712 } 3712 }
3713 } 3713 }
3714 3714
3715 UNREACHABLE(); 3715 UNREACHABLE();
3716 return 0; 3716 return 0;
3717 } 3717 }
3718 3718
3719 3719
3720 Object* SlicedString::SlicedStringFlatten() {
3721 // The SlicedString constructor should ensure that there are no
3722 // SlicedStrings that are constructed directly on top of other
3723 // SlicedStrings.
3724 String* buf = String::cast(buffer());
3725 StringShape buf_shape(buf);
3726 ASSERT(!buf_shape.IsSliced());
3727 if (buf_shape.IsCons()) {
3728 Object* ok = buf->Flatten(buf_shape);
3729 if (ok->IsFailure()) return ok;
3730 }
3731 return this;
3732 }
3733
3734
3735 template <typename sinkchar> 3720 template <typename sinkchar>
3736 void String::WriteToFlat(String* src, 3721 void String::WriteToFlat(String* src,
3737 StringShape src_shape, 3722 StringShape src_shape,
3738 sinkchar* sink, 3723 sinkchar* sink,
3739 int f, 3724 int f,
3740 int t) { 3725 int t) {
3741 String* source = src; 3726 String* source = src;
3742 StringShape shape = src_shape; 3727 StringShape shape = src_shape;
3743 int from = f; 3728 int from = f;
3744 int to = t; 3729 int to = t;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3968 } 3953 }
3969 } 3954 }
3970 } else { 3955 } else {
3971 string_compare_buffer_a.Reset(0, this); 3956 string_compare_buffer_a.Reset(0, this);
3972 return CompareStringContentsPartial(&string_compare_buffer_a, other); 3957 return CompareStringContentsPartial(&string_compare_buffer_a, other);
3973 } 3958 }
3974 } 3959 }
3975 3960
3976 3961
3977 bool String::MarkAsUndetectable() { 3962 bool String::MarkAsUndetectable() {
3978 StringShape shape(this); 3963 if (StringShape(this).IsSymbol()) return false;
3979 if (shape.IsSymbol()) return false;
3980 3964
3981 Map* map = this->map(); 3965 Map* map = this->map();
3982 if (map == Heap::short_string_map()) { 3966 if (map == Heap::short_string_map()) {
3983 this->set_map(Heap::undetectable_short_string_map()); 3967 this->set_map(Heap::undetectable_short_string_map());
3984 return true; 3968 return true;
3985 } else if (map == Heap::medium_string_map()) { 3969 } else if (map == Heap::medium_string_map()) {
3986 this->set_map(Heap::undetectable_medium_string_map()); 3970 this->set_map(Heap::undetectable_medium_string_map());
3987 return true; 3971 return true;
3988 } else if (map == Heap::long_string_map()) { 3972 } else if (map == Heap::long_string_map()) {
3989 this->set_map(Heap::undetectable_long_string_map()); 3973 this->set_map(Heap::undetectable_long_string_map());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4127 // Process the remaining characters without updating the array 4111 // Process the remaining characters without updating the array
4128 // index. 4112 // index.
4129 while (buffer->has_more()) { 4113 while (buffer->has_more()) {
4130 hasher.AddCharacterNoIndex(buffer->GetNext()); 4114 hasher.AddCharacterNoIndex(buffer->GetNext());
4131 } 4115 }
4132 4116
4133 return hasher.GetHashField(); 4117 return hasher.GetHashField();
4134 } 4118 }
4135 4119
4136 4120
4137 Object* String::Slice(StringShape shape, int start, int end) { 4121 Object* String::Slice(int start, int end) {
4122 StringShape shape(this);
4138 if (start == 0 && end == length(shape)) return this; 4123 if (start == 0 && end == length(shape)) return this;
4139 if (shape.representation_tag() == kSlicedStringTag) { 4124 if (shape.representation_tag() == kSlicedStringTag) {
4140 // Translate slices of a SlicedString into slices of the 4125 // Translate slices of a SlicedString into slices of the
4141 // underlying string buffer. 4126 // underlying string buffer.
4142 SlicedString* str = SlicedString::cast(this); 4127 SlicedString* str = SlicedString::cast(this);
4143 String* buf = str->buffer(); 4128 String* buf = str->buffer();
4144 return Heap::AllocateSlicedString(buf, 4129 return Heap::AllocateSlicedString(buf,
4145 StringShape(buf),
4146 str->start() + start, 4130 str->start() + start,
4147 str->start() + end); 4131 str->start() + end);
4148 } 4132 }
4149 Object* result = Heap::AllocateSlicedString(this, shape, start, end); 4133 Object* result = Heap::AllocateSlicedString(this, start, end);
4150 if (result->IsFailure()) { 4134 if (result->IsFailure()) {
4151 return result; 4135 return result;
4152 } 4136 }
4153 // Due to the way we retry after GC on allocation failure we are not allowed 4137 // Due to the way we retry after GC on allocation failure we are not allowed
4154 // to fail on allocation after this point. This is the one-allocation rule. 4138 // to fail on allocation after this point. This is the one-allocation rule.
4155 4139
4156 // Try to flatten a cons string that is under the sliced string. 4140 // Try to flatten a cons string that is under the sliced string.
4157 // This is to avoid memory leaks and possible stack overflows caused by 4141 // This is to avoid memory leaks and possible stack overflows caused by
4158 // building 'towers' of sliced strings on cons strings. 4142 // building 'towers' of sliced strings on cons strings.
4159 // This may fail due to an allocation failure (when a GC is needed), but it 4143 // This may fail due to an allocation failure (when a GC is needed), but it
(...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after
6920 // No break point. 6904 // No break point.
6921 if (break_point_objects()->IsUndefined()) return 0; 6905 if (break_point_objects()->IsUndefined()) return 0;
6922 // Single beak point. 6906 // Single beak point.
6923 if (!break_point_objects()->IsFixedArray()) return 1; 6907 if (!break_point_objects()->IsFixedArray()) return 1;
6924 // Multiple break points. 6908 // Multiple break points.
6925 return FixedArray::cast(break_point_objects())->length(); 6909 return FixedArray::cast(break_point_objects())->length();
6926 } 6910 }
6927 6911
6928 6912
6929 } } // namespace v8::internal 6913 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698