Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | 1932 // Check to see if 'lookup_name' matches 'name' as is or |
| 1933 // key separator is stripped from mangled_name. | 1933 // once the private key separator is stripped from name. |
| 1934 // | 1934 // |
| 1935 // Things are made more complicated by the fact that constructors are | 1935 // Things are made more complicated by the fact that constructors are |
| 1936 // added *after* the private suffix, so "foo@123.named" should match | 1936 // added *after* the private suffix, so "foo@123.named" should match |
| 1937 // "foo.named". | 1937 // "foo.named". |
| 1938 // | 1938 // |
| 1939 // Also, the private suffix can occur more than once in the name, as in: | 1939 // Also, the private suffix can occur more than once in the name, as in: |
| 1940 // | 1940 // |
| 1941 // _ReceivePortImpl@6be832b._internal@6be832b | 1941 // _ReceivePortImpl@6be832b._internal@6be832b |
| 1942 // | 1942 // |
| 1943 bool EqualsIgnoringPrivate(const String& mangled_name, | 1943 bool EqualsIgnoringPrivate(const String& name, const String& lookup_name) { |
|
srdjan
2012/07/13 23:22:23
Compare raws.
siva
2012/07/16 18:29:23
Done.
| |
| 1944 const String& bare_name) { | 1944 intptr_t name_len = name.Length(); |
| 1945 intptr_t mangled_len = mangled_name.Length(); | 1945 intptr_t lookup_name_len = lookup_name.Length(); |
| 1946 intptr_t bare_len = bare_name.Length(); | 1946 if (name_len == lookup_name_len) { |
| 1947 if (mangled_len < bare_len) { | 1947 for (intptr_t i = 0; i < name_len; i++) { |
| 1948 // No way they can match. | 1948 if (name.CharAt(i) != lookup_name.CharAt(i)) { |
| 1949 return false; | 1949 return false; |
| 1950 } | |
| 1951 } | |
| 1952 return true; | |
| 1950 } | 1953 } |
| 1954 if (name_len < lookup_name_len) { | |
| 1955 return false; // No way they can match. | |
| 1956 } | |
| 1957 intptr_t name_pos = 0; | |
| 1958 intptr_t lookup_name_pos = 0; | |
| 1959 while (name_pos < name_len) { | |
| 1960 int32_t name_char = name.CharAt(name_pos); | |
| 1961 name_pos++; | |
| 1951 | 1962 |
| 1952 intptr_t mangled_pos = 0; | 1963 if (name_char == Scanner::kPrivateKeySeparator) { |
| 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. | 1964 // Consume a private key separator. |
| 1960 while (mangled_pos < mangled_len && | 1965 while (name_pos < name_len && name.CharAt(name_pos) != '.') { |
| 1961 mangled_name.CharAt(mangled_pos) != '.') { | 1966 name_pos++; |
| 1962 mangled_pos++; | |
| 1963 } | 1967 } |
| 1964 | |
| 1965 // Resume matching characters. | 1968 // Resume matching characters. |
| 1966 continue; | 1969 continue; |
| 1967 } | 1970 } |
| 1968 if (bare_pos == bare_len || mangled_char != bare_name.CharAt(bare_pos)) { | 1971 if (lookup_name_pos == lookup_name_len || |
| 1972 name_char != lookup_name.CharAt(lookup_name_pos)) { | |
| 1969 return false; | 1973 return false; |
| 1970 } | 1974 } |
| 1971 bare_pos++; | 1975 lookup_name_pos++; |
| 1972 } | 1976 } |
| 1973 | 1977 |
| 1974 // The strings match if we have reached the end of both strings. | 1978 // We have reached the end of mangled_name string. |
| 1975 return (mangled_pos == mangled_len && | 1979 ASSERT(name_pos == name_len); |
| 1976 bare_pos == bare_len); | 1980 return (lookup_name_pos == lookup_name_len); |
| 1977 } | 1981 } |
| 1978 | 1982 |
| 1979 | 1983 |
| 1980 RawFunction* Class::LookupFunction(const String& name) const { | 1984 RawFunction* Class::LookupFunction(const String& name) const { |
| 1981 Isolate* isolate = Isolate::Current(); | 1985 Isolate* isolate = Isolate::Current(); |
| 1982 Array& funcs = Array::Handle(isolate, functions()); | 1986 Array& funcs = Array::Handle(isolate, functions()); |
| 1983 Function& function = Function::Handle(isolate, Function::null()); | 1987 Function& function = Function::Handle(isolate, Function::null()); |
| 1984 String& function_name = String::Handle(isolate, String::null()); | 1988 String& function_name = String::Handle(isolate, String::null()); |
| 1985 intptr_t len = funcs.Length(); | 1989 intptr_t len = funcs.Length(); |
| 1986 for (intptr_t i = 0; i < len; i++) { | 1990 for (intptr_t i = 0; i < len; i++) { |
| 1987 function ^= funcs.At(i); | 1991 function ^= funcs.At(i); |
| 1988 function_name ^= function.name(); | 1992 function_name ^= function.name(); |
| 1989 if (function_name.Equals(name) || | 1993 if (EqualsIgnoringPrivate(function_name, name)) { |
| 1990 EqualsIgnoringPrivate(function_name, name)) { | |
| 1991 return function.raw(); | 1994 return function.raw(); |
| 1992 } | 1995 } |
| 1993 } | 1996 } |
| 1994 | 1997 |
| 1995 // No function found. | 1998 // No function found. |
| 1996 return Function::null(); | 1999 return Function::null(); |
| 1997 } | 2000 } |
| 1998 | 2001 |
| 1999 | 2002 |
| 2000 RawFunction* Class::LookupGetterFunction(const String& name) const { | 2003 RawFunction* Class::LookupGetterFunction(const String& name) const { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2082 | 2085 |
| 2083 RawField* Class::LookupField(const String& name) const { | 2086 RawField* Class::LookupField(const String& name) const { |
| 2084 Isolate* isolate = Isolate::Current(); | 2087 Isolate* isolate = Isolate::Current(); |
| 2085 const Array& flds = Array::Handle(isolate, fields()); | 2088 const Array& flds = Array::Handle(isolate, fields()); |
| 2086 Field& field = Field::Handle(isolate, Field::null()); | 2089 Field& field = Field::Handle(isolate, Field::null()); |
| 2087 String& field_name = String::Handle(isolate, String::null()); | 2090 String& field_name = String::Handle(isolate, String::null()); |
| 2088 intptr_t len = flds.Length(); | 2091 intptr_t len = flds.Length(); |
| 2089 for (intptr_t i = 0; i < len; i++) { | 2092 for (intptr_t i = 0; i < len; i++) { |
| 2090 field ^= flds.At(i); | 2093 field ^= flds.At(i); |
| 2091 field_name ^= field.name(); | 2094 field_name ^= field.name(); |
| 2092 if (field_name.Equals(name) || EqualsIgnoringPrivate(field_name, name)) { | 2095 if (EqualsIgnoringPrivate(field_name, name)) { |
| 2093 return field.raw(); | 2096 return field.raw(); |
| 2094 } | 2097 } |
| 2095 } | 2098 } |
| 2096 // No field found. | 2099 // No field found. |
| 2097 return Field::null(); | 2100 return Field::null(); |
| 2098 } | 2101 } |
| 2099 | 2102 |
| 2100 | 2103 |
| 2101 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { | 2104 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { |
| 2102 Isolate* isolate = Isolate::Current(); | 2105 Isolate* isolate = Isolate::Current(); |
| (...skipping 6193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8296 return true; | 8299 return true; |
| 8297 } | 8300 } |
| 8298 | 8301 |
| 8299 if (!other.IsString() || other.IsNull()) { | 8302 if (!other.IsString() || other.IsNull()) { |
| 8300 return false; | 8303 return false; |
| 8301 } | 8304 } |
| 8302 | 8305 |
| 8303 const String& other_string = String::Cast(other); | 8306 const String& other_string = String::Cast(other); |
| 8304 if (this->HasHash() && other_string.HasHash() && | 8307 if (this->HasHash() && other_string.HasHash() && |
| 8305 (this->Hash() != other_string.Hash())) { | 8308 (this->Hash() != other_string.Hash())) { |
| 8306 // Both sides have a hash code and it does not match. | 8309 return false; // Both sides have a hash code and it does not match. |
| 8307 return false; | |
| 8308 } | 8310 } |
| 8309 | 8311 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 } | 8312 } |
| 8344 | 8313 |
| 8345 | 8314 |
| 8346 bool String::Equals(const char* str) const { | 8315 bool String::Equals(const char* str) const { |
| 8347 for (intptr_t i = 0; i < this->Length(); ++i) { | 8316 for (intptr_t i = 0; i < this->Length(); ++i) { |
| 8348 if (*str == '\0') { | 8317 if (*str == '\0') { |
| 8349 // Lengths don't match. | 8318 // Lengths don't match. |
| 8350 return false; | 8319 return false; |
| 8351 } | 8320 } |
| 8352 int32_t ch; | 8321 int32_t ch; |
| (...skipping 2390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10743 const String& str = String::Handle(pattern()); | 10712 const String& str = String::Handle(pattern()); |
| 10744 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10713 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10745 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10714 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10746 char* chars = reinterpret_cast<char*>( | 10715 char* chars = reinterpret_cast<char*>( |
| 10747 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10716 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10748 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10717 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10749 return chars; | 10718 return chars; |
| 10750 } | 10719 } |
| 10751 | 10720 |
| 10752 } // namespace dart | 10721 } // namespace dart |
| OLD | NEW |