diff --git a/src/builtins/array-join.tq b/src/builtins/array-join.tq index 9e1993b99f..4923b8ba25 100644 --- a/src/builtins/array-join.tq +++ b/src/builtins/array-join.tq @@ -222,6 +222,27 @@ module array { assert(IsValidPositiveSmi(buffer.totalStringLength)); if (buffer.totalStringLength == 0) return kEmptyString; + // Fast path when there's only one buffer element. + if (buffer.index == 1) { + const fixedArray: FixedArray = buffer.fixedArray; + typeswitch (fixedArray[0]) { + // When the element is a string, just return it and completely avoid + // allocating another string. + case (str: String): { + return str; + } + + // When the element is a smi, use StringRepeat to quickly build a memory + // efficient separator repeated string. + case (nofSeparators: Number): { + return StringRepeat(context, sep, nofSeparators); + } + case (obj: Object): { + unreachable; + } + } + } + const length: uint32 = Convert(Unsigned(buffer.totalStringLength)); const r: String = buffer.isOneByte ? AllocateSeqOneByteString(length) : AllocateSeqTwoByteString(length); diff --git a/test/inspector/runtime/console-messages-limits-expected.txt b/test/inspector/runtime/console-messages-limits-expected.txt index 3d1cd9f526..73433e3f54 100644 --- a/test/inspector/runtime/console-messages-limits-expected.txt +++ b/test/inspector/runtime/console-messages-limits-expected.txt @@ -4,4 +4,4 @@ Running test: testMaxConsoleMessagesCount Messages reported: 1000 Running test: testMaxConsoleMessagesV8Size -Messages reported: 3 +Messages reported: 5