Index: src/compiler/js-native-context-specialization.cc |
diff --git a/src/compiler/js-native-context-specialization.cc b/src/compiler/js-native-context-specialization.cc |
index 57e933b1aa0c3b28db60ff0567db144605787a47..e6f4194cfeb5173a767ec7b21d5d48b738a9d56b 100644 |
--- a/src/compiler/js-native-context-specialization.cc |
+++ b/src/compiler/js-native-context-specialization.cc |
@@ -688,19 +688,29 @@ Reduction JSNativeContextSpecialization::ReduceKeyedAccess( |
// Strings are immutable in JavaScript. |
if (access_mode == AccessMode::kStore) return NoChange(); |
- // Ensure that {index} is less than {receiver} length. |
- Node* length = jsgraph()->Constant(string->length()); |
- index = effect = graph()->NewNode(simplified()->CheckBounds(), index, |
- length, effect, control); |
- |
- // Load the character from the {receiver}. |
- value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver, |
- index, control); |
- |
- // Return it as a single character string. |
- value = graph()->NewNode(simplified()->StringFromCharCode(), value); |
- ReplaceWithValue(node, value, effect, control); |
- return Replace(value); |
+ // Properly deal with constant {index}. |
+ NumberMatcher mindex(index); |
+ if (mindex.IsInteger() && mindex.IsInRange(0.0, string->length() - 1)) { |
+ // Constant-fold the {index} access to {string}. |
+ Node* value = |
+ jsgraph()->Constant(string->Get(static_cast<int>(mindex.Value()))); |
+ ReplaceWithValue(node, value, effect, control); |
+ return Replace(value); |
+ } else if (flags() & kDeoptimizationEnabled) { |
+ // Ensure that {index} is less than {receiver} length. |
+ Node* length = jsgraph()->Constant(string->length()); |
+ index = effect = graph()->NewNode(simplified()->CheckBounds(), index, |
+ length, effect, control); |
+ |
+ // Load the character from the {receiver}. |
+ value = graph()->NewNode(simplified()->StringCharCodeAt(), receiver, |
+ index, control); |
+ |
+ // Return it as a single character string. |
+ value = graph()->NewNode(simplified()->StringFromCharCode(), value); |
+ ReplaceWithValue(node, value, effect, control); |
+ return Replace(value); |
+ } |
} |
} |