Chromium Code Reviews| Index: runtime/vm/flow_graph_optimizer.cc |
| =================================================================== |
| --- runtime/vm/flow_graph_optimizer.cc (revision 31147) |
| +++ runtime/vm/flow_graph_optimizer.cc (working copy) |
| @@ -6630,7 +6630,37 @@ |
| void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) { |
| - SetValue(instr, non_constant_); |
| + const Object& array_obj = instr->array()->definition()->constant_value(); |
| + const Object& index_obj = instr->index()->definition()->constant_value(); |
| + if (IsNonConstant(array_obj) || IsNonConstant(index_obj)) { |
| + SetValue(instr, non_constant_); |
| + } else if (IsConstant(array_obj) && IsConstant(index_obj)) { |
| + // Need index to be Smi and array to be either String or an immutable array. |
| + if (!index_obj.IsSmi()) { |
| + // Should not occur. |
| + SetValue(instr, non_constant_); |
| + return; |
| + } |
| + const intptr_t index = Smi::Cast(index_obj).Value(); |
| + if (index >= 0) { |
| + if (array_obj.IsString()) { |
| + const String& str = String::Cast(array_obj); |
| + if (str.Length() > index) { |
| + SetValue(instr, Smi::Handle(Smi::New(str.CharAt(index)))); |
| + return; |
| + } |
| + } else if (array_obj.IsArray()) { |
| + const Array& a = Array::Cast(array_obj); |
| + if ((a.Length() > index) && a.IsImmutable()) { |
|
Cutch
2013/12/18 05:21:19
Is IsImmutable needed for a constant array?
srdjan
2013/12/18 16:40:01
I believe it could be possible for constant propag
|
| + Instance& result = Instance::Handle(); |
| + result ^= a.At(index); |
| + SetValue(instr, result); |
| + return; |
| + } |
| + } |
| + } |
| + SetValue(instr, non_constant_); |
| + } |
| } |