aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-10-26 21:48:03 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-10-26 21:48:03 +0000
commitabf63457102b4a4e223c2f60f90886c225f1390a (patch)
tree63a80eb4feb8127c94420e9d30996dc13bbb1cb4
parent38187d6a56326d0d6339f09c1ef21d52174d95a8 (diff)
Speed up isCString()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31206 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/Constants.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index ce29a21f86..9c92b90778 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1077,11 +1077,21 @@ bool ConstantArray::isString() const {
/// isString) and it ends in a null byte \0 and does not contains any other
/// null bytes except its terminator.
bool ConstantArray::isCString() const {
- if (!isString()) return false;
- // This is safe because a ConstantArray cannot be a zero array.
- for (unsigned i = 0, e = getNumOperands()-1; i != e; ++i)
- if (cast<ConstantInt>(getOperand(i))->getZExtValue() == 0)
+ // Check the element type for sbyte or ubyte...
+ if (getType()->getElementType() != Type::UByteTy &&
+ getType()->getElementType() != Type::SByteTy)
+ return false;
+ Constant *Zero = Constant::getNullValue(getOperand(0)->getType());
+ // Last element must be a null.
+ if (getOperand(getNumOperands()-1) != Zero)
+ return false;
+ // Other elements must be non-null integers.
+ for (unsigned i = 0, e = getNumOperands()-1; i != e; ++i) {
+ if (!isa<ConstantInt>(getOperand(i)))
return false;
+ if (getOperand(i) == Zero)
+ return false;
+ }
return true;
}