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

Unified Diff: runtime/vm/object.cc

Issue 10687004: Implement method and variable reflection in dart:mirrors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 9071)
+++ runtime/vm/object.cc (working copy)
@@ -1931,26 +1931,57 @@
}
-static bool MatchesPrivateName(const String& name, const String& private_name) {
- intptr_t name_len = name.Length();
- intptr_t private_len = private_name.Length();
- // The private_name must at least have room for the separator and one key
- // character.
- if ((name_len < (private_len + 2)) || (name_len == 0) || (private_len == 0)) {
+// Check to see if munged_name is equal to bare_name once the private
cshapiro 2012/06/28 23:57:47 Maybe just make this an equality test and eliminat
turnidge 2012/07/09 23:45:17 Done.
+// key separator is stripped from munged_name.
+//
+// If there is no private key separator in munged name, the function
+// returns false even if the strings are identical.
+//
+// Things are made more complicated by the fact that constructors are
+// added *after* the private suffix, so "foo@123.named" should match
+// "foo.named".
+//
+// Also, the private suffix can occur more than once in the name, as in:
+//
+// _ReceivePortImpl@6be832b._internal@6be832b
+//
+bool MatchesIgnorePrivate(const String& munged_name, const String& bare_name) {
cshapiro 2012/06/28 23:57:47 Ignoring? Mangled?
turnidge 2012/07/09 23:45:17 Done.
+ intptr_t munged_len = munged_name.Length();
+ intptr_t bare_len = bare_name.Length();
+ if (munged_len <= bare_len) {
+ // No way they can match.
return false;
}
- // Check for the private key separator.
- if (name.CharAt(private_len) != Scanner::kPrivateKeySeparator) {
- return false;
- }
+ bool found_private_key = false;
+ intptr_t munged_pos = 0;
+ intptr_t bare_pos = 0;
+ while (munged_pos < munged_len) {
+ int32_t munged_char = munged_name.CharAt(munged_pos);
+ munged_pos++;
- for (intptr_t i = 0; i < private_len; i++) {
- if (name.CharAt(i) != private_name.CharAt(i)) {
+ if (munged_char == Scanner::kPrivateKeySeparator) {
+ // Consume a private key separator.
+ while (munged_pos < munged_len &&
+ munged_name.CharAt(munged_pos) != '.') {
+ munged_pos++;
+ }
+ found_private_key = true;
+
+ // Resume matching characters.
+ continue;
+ }
+ if (bare_pos == bare_len || munged_char != bare_name.CharAt(bare_pos)) {
return false;
}
+ bare_pos++;
}
- return true;
+
+ // The strings match if we found the private key and we reached the
+ // end of both strings.
+ return (found_private_key &&
+ munged_pos == munged_len &&
+ bare_pos == bare_len);
}
@@ -1963,7 +1994,8 @@
for (intptr_t i = 0; i < len; i++) {
function ^= funcs.At(i);
function_name ^= function.name();
- if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) {
+ if (function_name.Equals(name) ||
+ MatchesIgnorePrivate(function_name, name)) {
return function.raw();
}
}
@@ -2065,7 +2097,7 @@
for (intptr_t i = 0; i < len; i++) {
field ^= flds.At(i);
field_name ^= field.name();
- if (field_name.Equals(name) || MatchesPrivateName(field_name, name)) {
+ if (field_name.Equals(name) || MatchesIgnorePrivate(field_name, name)) {
return field.raw();
}
}

Powered by Google App Engine
This is Rietveld 408576698