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

Side by Side Diff: vm/object.cc

Issue 10785007: Minor changes based on the profile while running dart2js compile all. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
« vm/object.h ('K') | « vm/object.h ('k') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 } 1922 }
1923 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { 1923 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) {
1924 if (name.CharAt(j) != accessor_name.CharAt(i)) { 1924 if (name.CharAt(j) != accessor_name.CharAt(i)) {
1925 return false; 1925 return false;
1926 } 1926 }
1927 } 1927 }
1928 return true; 1928 return true;
1929 } 1929 }
1930 1930
1931 1931
1932 // Check to see if mangled_name is equal to bare_name once the private
1933 // key separator is stripped from mangled_name.
1934 //
1935 // Things are made more complicated by the fact that constructors are
1936 // added *after* the private suffix, so "foo@123.named" should match
1937 // "foo.named".
1938 //
1939 // Also, the private suffix can occur more than once in the name, as in:
1940 //
1941 // _ReceivePortImpl@6be832b._internal@6be832b
1942 //
1943 bool EqualsIgnoringPrivate(const String& mangled_name,
1944 const String& bare_name) {
1945 intptr_t mangled_len = mangled_name.Length();
1946 intptr_t bare_len = bare_name.Length();
1947 if (mangled_len < bare_len) {
1948 // No way they can match.
1949 return false;
1950 }
1951
1952 intptr_t mangled_pos = 0;
1953 intptr_t bare_pos = 0;
1954 while (mangled_pos < mangled_len) {
1955 int32_t mangled_char = mangled_name.CharAt(mangled_pos);
1956 mangled_pos++;
1957
1958 if (mangled_char == Scanner::kPrivateKeySeparator) {
1959 // Consume a private key separator.
1960 while (mangled_pos < mangled_len &&
1961 mangled_name.CharAt(mangled_pos) != '.') {
1962 mangled_pos++;
1963 }
1964
1965 // Resume matching characters.
1966 continue;
1967 }
1968 if (bare_pos == bare_len || mangled_char != bare_name.CharAt(bare_pos)) {
1969 return false;
1970 }
1971 bare_pos++;
1972 }
1973
1974 // The strings match if we have reached the end of both strings.
1975 return (mangled_pos == mangled_len &&
1976 bare_pos == bare_len);
1977 }
1978
1979
1980 RawFunction* Class::LookupFunction(const String& name) const { 1932 RawFunction* Class::LookupFunction(const String& name) const {
1981 Isolate* isolate = Isolate::Current(); 1933 Isolate* isolate = Isolate::Current();
1934 ASSERT(name.IsOneByteString());
1935 const OneByteString& lookup_name = OneByteString::Cast(name);
1982 Array& funcs = Array::Handle(isolate, functions()); 1936 Array& funcs = Array::Handle(isolate, functions());
1983 Function& function = Function::Handle(isolate, Function::null()); 1937 Function& function = Function::Handle(isolate, Function::null());
1984 String& function_name = String::Handle(isolate, String::null()); 1938 OneByteString& function_name =
1939 OneByteString::Handle(isolate, OneByteString::null());
1985 intptr_t len = funcs.Length(); 1940 intptr_t len = funcs.Length();
1986 for (intptr_t i = 0; i < len; i++) { 1941 for (intptr_t i = 0; i < len; i++) {
1987 function ^= funcs.At(i); 1942 function ^= funcs.At(i);
1988 function_name ^= function.name(); 1943 function_name ^= function.name();
1989 if (function_name.Equals(name) || 1944 if (function_name.EqualsIgnoringPrivate(lookup_name)) {
1990 EqualsIgnoringPrivate(function_name, name)) {
1991 return function.raw(); 1945 return function.raw();
1992 } 1946 }
1993 } 1947 }
1994 1948
1995 // No function found. 1949 // No function found.
1996 return Function::null(); 1950 return Function::null();
1997 } 1951 }
1998 1952
1999 1953
2000 RawFunction* Class::LookupGetterFunction(const String& name) const { 1954 RawFunction* Class::LookupGetterFunction(const String& name) const {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 } 2029 }
2076 return field.raw(); 2030 return field.raw();
2077 } 2031 }
2078 // No field found. 2032 // No field found.
2079 return Field::null(); 2033 return Field::null();
2080 } 2034 }
2081 2035
2082 2036
2083 RawField* Class::LookupField(const String& name) const { 2037 RawField* Class::LookupField(const String& name) const {
2084 Isolate* isolate = Isolate::Current(); 2038 Isolate* isolate = Isolate::Current();
2039 ASSERT(name.IsOneByteString());
2040 const OneByteString& lookup_name = OneByteString::Cast(name);
2085 const Array& flds = Array::Handle(isolate, fields()); 2041 const Array& flds = Array::Handle(isolate, fields());
2086 Field& field = Field::Handle(isolate, Field::null()); 2042 Field& field = Field::Handle(isolate, Field::null());
2087 String& field_name = String::Handle(isolate, String::null()); 2043 OneByteString& field_name =
2044 OneByteString::Handle(isolate, OneByteString::null());
2088 intptr_t len = flds.Length(); 2045 intptr_t len = flds.Length();
2089 for (intptr_t i = 0; i < len; i++) { 2046 for (intptr_t i = 0; i < len; i++) {
2090 field ^= flds.At(i); 2047 field ^= flds.At(i);
2091 field_name ^= field.name(); 2048 field_name ^= field.name();
2092 if (field_name.Equals(name) || EqualsIgnoringPrivate(field_name, name)) { 2049 if (field_name.EqualsIgnoringPrivate(lookup_name)) {
2093 return field.raw(); 2050 return field.raw();
2094 } 2051 }
2095 } 2052 }
2096 // No field found. 2053 // No field found.
2097 return Field::null(); 2054 return Field::null();
2098 } 2055 }
2099 2056
2100 2057
2101 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { 2058 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const {
2102 Isolate* isolate = Isolate::Current(); 2059 Isolate* isolate = Isolate::Current();
(...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after
4003 Heap::kOld); 3960 Heap::kOld);
4004 return reinterpret_cast<RawFunction*>(raw); 3961 return reinterpret_cast<RawFunction*>(raw);
4005 } 3962 }
4006 3963
4007 3964
4008 RawFunction* Function::New(const String& name, 3965 RawFunction* Function::New(const String& name,
4009 RawFunction::Kind kind, 3966 RawFunction::Kind kind,
4010 bool is_static, 3967 bool is_static,
4011 bool is_const, 3968 bool is_const,
4012 intptr_t token_pos) { 3969 intptr_t token_pos) {
3970 ASSERT(name.IsOneByteString());
4013 const Function& result = Function::Handle(Function::New()); 3971 const Function& result = Function::Handle(Function::New());
4014 result.set_parameter_types(Array::Handle(Array::Empty())); 3972 result.set_parameter_types(Array::Handle(Array::Empty()));
4015 result.set_parameter_names(Array::Handle(Array::Empty())); 3973 result.set_parameter_names(Array::Handle(Array::Empty()));
4016 result.set_name(name); 3974 result.set_name(name);
4017 result.set_kind(kind); 3975 result.set_kind(kind);
4018 result.set_is_static(is_static); 3976 result.set_is_static(is_static);
4019 result.set_is_const(is_const); 3977 result.set_is_const(is_const);
4020 result.set_token_pos(token_pos); 3978 result.set_token_pos(token_pos);
4021 result.set_end_token_pos(token_pos); 3979 result.set_end_token_pos(token_pos);
4022 result.set_num_fixed_parameters(0); 3980 result.set_num_fixed_parameters(0);
4023 result.set_num_optional_parameters(0); 3981 result.set_num_optional_parameters(0);
4024 result.set_usage_counter(0); 3982 result.set_usage_counter(0);
4025 result.set_deoptimization_counter(0); 3983 result.set_deoptimization_counter(0);
4026 result.set_is_optimizable(true); 3984 result.set_is_optimizable(true);
4027 result.set_is_native(false); 3985 result.set_is_native(false);
4028 return result.raw(); 3986 return result.raw();
4029 } 3987 }
4030 3988
4031 3989
4032 RawFunction* Function::NewClosureFunction(const String& name, 3990 RawFunction* Function::NewClosureFunction(const String& name,
4033 const Function& parent, 3991 const Function& parent,
4034 intptr_t token_pos) { 3992 intptr_t token_pos) {
3993 ASSERT(name.IsOneByteString());
4035 ASSERT(!parent.IsNull()); 3994 ASSERT(!parent.IsNull());
4036 const Class& parent_class = Class::Handle(parent.owner()); 3995 const Class& parent_class = Class::Handle(parent.owner());
4037 ASSERT(!parent_class.IsNull()); 3996 ASSERT(!parent_class.IsNull());
4038 const Function& result = Function::Handle( 3997 const Function& result = Function::Handle(
4039 Function::New(name, 3998 Function::New(name,
4040 RawFunction::kClosureFunction, 3999 RawFunction::kClosureFunction,
4041 /* is_static = */ parent.is_static(), 4000 /* is_static = */ parent.is_static(),
4042 /* is_const = */ false, 4001 /* is_const = */ false,
4043 token_pos)); 4002 token_pos));
4044 result.set_parent_function(parent); 4003 result.set_parent_function(parent);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
4360 Field::InstanceSize(), 4319 Field::InstanceSize(),
4361 Heap::kOld); 4320 Heap::kOld);
4362 return reinterpret_cast<RawField*>(raw); 4321 return reinterpret_cast<RawField*>(raw);
4363 } 4322 }
4364 4323
4365 4324
4366 RawField* Field::New(const String& name, 4325 RawField* Field::New(const String& name,
4367 bool is_static, 4326 bool is_static,
4368 bool is_final, 4327 bool is_final,
4369 intptr_t token_pos) { 4328 intptr_t token_pos) {
4329 ASSERT(name.IsOneByteString());
4370 const Field& result = Field::Handle(Field::New()); 4330 const Field& result = Field::Handle(Field::New());
4371 result.set_name(name); 4331 result.set_name(name);
4372 result.set_is_static(is_static); 4332 result.set_is_static(is_static);
4373 if (is_static) { 4333 if (is_static) {
4374 result.set_value(Instance::Handle()); 4334 result.set_value(Instance::Handle());
4375 } else { 4335 } else {
4376 result.SetOffset(0); 4336 result.SetOffset(0);
4377 } 4337 }
4378 result.set_is_final(is_final); 4338 result.set_is_final(is_final);
4379 result.set_token_pos(token_pos); 4339 result.set_token_pos(token_pos);
(...skipping 3916 matching lines...) Expand 10 before | Expand all | Expand 10 after
8296 return true; 8256 return true;
8297 } 8257 }
8298 8258
8299 if (!other.IsString() || other.IsNull()) { 8259 if (!other.IsString() || other.IsNull()) {
8300 return false; 8260 return false;
8301 } 8261 }
8302 8262
8303 const String& other_string = String::Cast(other); 8263 const String& other_string = String::Cast(other);
8304 if (this->HasHash() && other_string.HasHash() && 8264 if (this->HasHash() && other_string.HasHash() &&
8305 (this->Hash() != other_string.Hash())) { 8265 (this->Hash() != other_string.Hash())) {
8306 // Both sides have a hash code and it does not match. 8266 return false; // Both sides have a hash code and it does not match.
8307 return false;
8308 } 8267 }
8309 8268 return Equals(other_string, 0, other_string.Length());
8310 intptr_t len = this->Length();
8311 if (len != other_string.Length()) {
8312 // Lengths don't match.
8313 return false;
8314 }
8315
8316 for (intptr_t i = 0; i < len; i++) {
8317 if (this->CharAt(i) != other_string.CharAt(i)) {
8318 return false;
8319 }
8320 }
8321 return true;
8322 }
8323
8324
8325 bool String::Equals(const String& str,
8326 intptr_t begin_index,
8327 intptr_t len) const {
8328 ASSERT(begin_index >= 0);
8329 ASSERT(begin_index == 0 || begin_index < str.Length());
8330 ASSERT(len >= 0);
8331 ASSERT(len <= str.Length());
8332 if (len != this->Length()) {
8333 // Lengths don't match.
8334 return false;
8335 }
8336
8337 for (intptr_t i = 0; i < len; i++) {
8338 if (this->CharAt(i) != str.CharAt(begin_index + i)) {
8339 return false;
8340 }
8341 }
8342 return true;
8343 } 8269 }
8344 8270
8345 8271
8346 bool String::Equals(const char* str) const { 8272 bool String::Equals(const char* str) const {
8347 for (intptr_t i = 0; i < this->Length(); ++i) { 8273 for (intptr_t i = 0; i < this->Length(); ++i) {
8348 if (*str == '\0') { 8274 if (*str == '\0') {
8349 // Lengths don't match. 8275 // Lengths don't match.
8350 return false; 8276 return false;
8351 } 8277 }
8352 int32_t ch; 8278 int32_t ch;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
9062 *(dststr.CharAddr(index)) = *CharAddr(i); 8988 *(dststr.CharAddr(index)) = *CharAddr(i);
9063 index += 1; 8989 index += 1;
9064 } 8990 }
9065 } 8991 }
9066 return dststr.raw(); 8992 return dststr.raw();
9067 } 8993 }
9068 return OneByteString::null(); 8994 return OneByteString::null();
9069 } 8995 }
9070 8996
9071 8997
8998 // Check to see if 'name' matches 'this' as is or
8999 // once the private key separator is stripped from name.
9000 //
9001 // Things are made more complicated by the fact that constructors are
9002 // added *after* the private suffix, so "foo@123.named" should match
9003 // "foo.named".
9004 //
9005 // Also, the private suffix can occur more than once in the name, as in:
9006 //
9007 // _ReceivePortImpl@6be832b._internal@6be832b
9008 //
9009 bool OneByteString::EqualsIgnoringPrivate(const OneByteString& name) const {
9010 if (raw() == name.raw()) {
9011 return true; // Both handles point to the same raw instance.
9012 }
9013 intptr_t len = Length();
9014 intptr_t name_len = name.Length();
9015 if (len == name_len) {
9016 for (intptr_t i = 0; i < len; i++) {
9017 if (*(CharAddr(i)) != *(name.CharAddr(i))) {
9018 return false;
9019 }
9020 }
9021 return true;
9022 }
9023 if (len < name_len) {
9024 return false; // No way they can match.
9025 }
9026 intptr_t pos = 0;
9027 intptr_t name_pos = 0;
9028 while (pos < len) {
9029 int32_t ch = *(CharAddr(pos));
9030 pos++;
9031
9032 if (ch == Scanner::kPrivateKeySeparator) {
9033 // Consume a private key separator.
9034 while (pos < len && *(CharAddr(pos)) != '.') {
9035 pos++;
9036 }
9037 // Resume matching characters.
9038 continue;
9039 }
9040 if (name_pos == name_len || ch != *(name.CharAddr(name_pos))) {
9041 return false;
9042 }
9043 name_pos++;
9044 }
9045
9046 // We have reached the end of mangled_name string.
9047 ASSERT(pos == len);
9048 return (name_pos == name_len);
9049 }
9050
9051
9072 RawOneByteString* OneByteString::New(intptr_t len, 9052 RawOneByteString* OneByteString::New(intptr_t len,
9073 Heap::Space space) { 9053 Heap::Space space) {
9074 Isolate* isolate = Isolate::Current(); 9054 Isolate* isolate = Isolate::Current();
9075 9055
9076 const Class& cls = 9056 const Class& cls =
9077 Class::Handle(isolate->object_store()->one_byte_string_class()); 9057 Class::Handle(isolate->object_store()->one_byte_string_class());
9078 OneByteString& result = OneByteString::Handle(); 9058 OneByteString& result = OneByteString::Handle();
9079 { 9059 {
9080 RawObject* raw = Object::Allocate(cls, 9060 RawObject* raw = Object::Allocate(cls,
9081 OneByteString::InstanceSize(len), 9061 OneByteString::InstanceSize(len),
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
10743 const String& str = String::Handle(pattern()); 10723 const String& str = String::Handle(pattern());
10744 const char* format = "JSRegExp: pattern=%s flags=%s"; 10724 const char* format = "JSRegExp: pattern=%s flags=%s";
10745 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10725 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10746 char* chars = reinterpret_cast<char*>( 10726 char* chars = reinterpret_cast<char*>(
10747 Isolate::Current()->current_zone()->Allocate(len + 1)); 10727 Isolate::Current()->current_zone()->Allocate(len + 1));
10748 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10728 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10749 return chars; 10729 return chars;
10750 } 10730 }
10751 10731
10752 } // namespace dart 10732 } // namespace dart
OLDNEW
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698