From 0dbdaf6efd853a0a110e3fdd2d5ebeb989127564 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 31 Mar 2014 21:46:05 +0000 Subject: [PATCH] MS ABI: Simplify endian swapping code No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205250 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 0fc7d5c8ec..4f6ee315a7 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -2388,31 +2388,15 @@ void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL, auto GetLittleEndianByte = [&Mangler, &SL](unsigned Index) { unsigned CharByteWidth = SL->getCharByteWidth(); uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); - if (CharByteWidth == 1) { - return static_cast(CodeUnit); - } else if (CharByteWidth == 2) { - if (Index % 2) - return static_cast((CodeUnit >> 8) & 0xff); - else - return static_cast(CodeUnit & 0xff); - } else { - llvm_unreachable("unsupported CharByteWidth"); - } + unsigned OffsetInCodeUnit = Index % CharByteWidth; + return static_cast((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff); }; auto GetBigEndianByte = [&Mangler, &SL](unsigned Index) { unsigned CharByteWidth = SL->getCharByteWidth(); uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth); - if (CharByteWidth == 1) { - return static_cast(CodeUnit); - } else if (CharByteWidth == 2) { - if (Index % 2) - return static_cast(CodeUnit & 0xff); - else - return static_cast((CodeUnit >> 8) & 0xff); - } else { - llvm_unreachable("unsupported CharByteWidth"); - } + unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth); + return static_cast((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff); }; // CRC all the bytes of the StringLiteral. -- 2.40.0