From e91e0ae772004912285ccc3848b27208da8c045b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 7 Feb 2012 00:39:21 +0000 Subject: [PATCH] tidy up code, make the common case (1-byte strings) come first git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149942 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Expr.h | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 33f95afd32..f78138c16d 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1369,31 +1369,25 @@ public: /// Allow clients that need the byte representation, such as ASTWriterStmt /// ::VisitStringLiteral(), access. StringRef getBytes() const { - // FIXME: StringRef may not be the right type to use as a result for this... - assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) - && "unsupported CharByteWidth"); - if (CharByteWidth==4) { + // FIXME: StringRef may not be the right type to use as a result for this. + if (CharByteWidth == 1) + return StringRef(StrData.asChar, getByteLength()); + if (CharByteWidth == 4) return StringRef(reinterpret_cast(StrData.asUInt32), getByteLength()); - } else if (CharByteWidth==2) { - return StringRef(reinterpret_cast(StrData.asUInt16), - getByteLength()); - } else { - return StringRef(StrData.asChar, getByteLength()); - } + assert(CharByteWidth == 2 && "unsupported CharByteWidth"); + return StringRef(reinterpret_cast(StrData.asUInt16), + getByteLength()); } uint32_t getCodeUnit(size_t i) const { - assert(i(StrData.asChar[i]); - } + if (CharByteWidth == 4) + return StrData.asUInt32[i]; + assert(CharByteWidth == 2 && "unsupported CharByteWidth"); + return StrData.asUInt16[i]; } unsigned getByteLength() const { return CharByteWidth*Length; } -- 2.40.0