summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-02-07 00:39:21 +0000
committerChris Lattner <sabre@nondot.org>2012-02-07 00:39:21 +0000
commit8573dc7e1fbc5d7c8687ede1b34078b09ad1e07f (patch)
tree227fd2abcc4e94e9e7697a12b89bba362fe27ea4 /clang
parent76b292f5babb16e40d31d8d014dcd2ceb4ee688c (diff)
downloadbcm5719-llvm-8573dc7e1fbc5d7c8687ede1b34078b09ad1e07f.tar.gz
bcm5719-llvm-8573dc7e1fbc5d7c8687ede1b34078b09ad1e07f.zip
tidy up code, make the common case (1-byte strings) come first
llvm-svn: 149942
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/Expr.h32
1 files changed, 13 insertions, 19 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 33f95afd32a..f78138c16d7 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/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<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; }
OpenPOWER on IntegriCloud