[cfe-commits] r149942 - /cfe/trunk/include/clang/AST/Expr.h
Chris Lattner
sabre at nondot.org
Mon Feb 6 16:39:21 PST 2012
Author: lattner
Date: Mon Feb 6 18:39:21 2012
New Revision: 149942
URL: http://llvm.org/viewvc/llvm-project?rev=149942&view=rev
Log:
tidy up code, make the common case (1-byte strings) come first
Modified:
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=149942&r1=149941&r2=149942&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Feb 6 18:39:21 2012
@@ -1369,31 +1369,25 @@
/// 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<const char*>(StrData.asUInt32),
getByteLength());
- } else if (CharByteWidth==2) {
- return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
- getByteLength());
- } else {
- return StringRef(StrData.asChar, getByteLength());
- }
+ assert(CharByteWidth == 2 && "unsupported CharByteWidth");
+ return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
+ getByteLength());
}
uint32_t getCodeUnit(size_t i) const {
- assert(i<Length && "out of bounds access");
- assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4)
- && "unsupported CharByteWidth");
- if (CharByteWidth==4) {
- return StrData.asUInt32[i];
- } else if (CharByteWidth==2) {
- return StrData.asUInt16[i];
- } else {
+ assert(i < Length && "out of bounds access");
+ if (CharByteWidth == 1)
return static_cast<unsigned char>(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; }
More information about the cfe-commits
mailing list