Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Compilation/ILEmitter.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,15 +1276,17 @@ private void EmitPromotedStringCharCodeAt(LocalBuilder sb, List<Expr> arguments)
IL.Emit(OpCodes.Ldloc, idxLocal);
IL.Emit(OpCodes.Callvirt, getChars);
IL.Emit(OpCodes.Conv_R8);
IL.Emit(OpCodes.Box, _ctx.Types.Double);
IL.Emit(OpCodes.Br, end);

IL.MarkLabel(oob);
IL.Emit(OpCodes.Ldc_R8, double.NaN);
IL.Emit(OpCodes.Box, _ctx.Types.Double);

// #859: leave a raw float64 (both branches push double) instead of boxing. The result is
// typically consumed by a numeric op (`sum + s.charCodeAt(i)`), whose EnsureDouble is then a
// no-op; a boxed-object consumer re-boxes via EmitBoxIfNeeded (which checks StackType). This
// elides the per-char `box Double` (a heap allocation) plus the consumer's `ConvertToNumber`.
IL.MarkLabel(end);
SetStackUnknown();
SetStackType(StackType.Double);
}

/// <summary>
Expand Down
Loading