From bd9fbc0cd30e8a70bb64a9ca212d2c38e6486a5b Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 31 Oct 2025 02:15:35 +0000 Subject: [PATCH] Remove dead ucs2 case labels after normalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since ucs2 is normalized to utf16le at the start of jsBufferFunction_transcode, all `case BufferEncodingType::ucs2:` labels in the switch statements are unreachable dead code. Removed them and added clarifying comments. No functional changes - all tests still pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/bun.js/bindings/JSBuffer.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index e59269c3a8..8795c2cdd2 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -2145,9 +2145,8 @@ static JSC::JSUint8Array* transcodeBuffer( switch (fromEncoding) { case BufferEncodingType::utf8: { switch (toEncoding) { - case BufferEncodingType::utf16le: - case BufferEncodingType::ucs2: { - // UTF-8 to UTF-16LE + case BufferEncodingType::utf16le: { + // UTF-8 to UTF-16LE (ucs2 normalized to utf16le earlier) size_t expectedLength = simdutf::utf16_length_from_utf8(reinterpret_cast(source), sourceLength); result = createUninitializedBuffer(lexicalGlobalObject, expectedLength * 2); RETURN_IF_EXCEPTION(scope, nullptr); @@ -2198,9 +2197,8 @@ static JSC::JSUint8Array* transcodeBuffer( } break; } - case BufferEncodingType::utf16le: - case BufferEncodingType::ucs2: { - // Source is UTF-16LE + case BufferEncodingType::utf16le: { + // Source is UTF-16LE (ucs2 normalized to utf16le earlier) size_t utf16Length = sourceLength / 2; const char16_t* utf16Source = reinterpret_cast(source); @@ -2280,9 +2278,8 @@ static JSC::JSUint8Array* transcodeBuffer( return result; } - case BufferEncodingType::utf16le: - case BufferEncodingType::ucs2: { - // Latin1 to UTF-16LE + case BufferEncodingType::utf16le: { + // Latin1 to UTF-16LE (ucs2 normalized to utf16le earlier) result = createUninitializedBuffer(lexicalGlobalObject, sourceLength * 2); RETURN_IF_EXCEPTION(scope, nullptr);