diff options
| author | Evan Cheng <evan.cheng@apple.com> | 2006-10-26 21:48:03 +0000 |
|---|---|---|
| committer | Evan Cheng <evan.cheng@apple.com> | 2006-10-26 21:48:03 +0000 |
| commit | e974da6bb71d06405472468a4257099205685c32 (patch) | |
| tree | 8c1c0066680253721ddd095baff9a9a7bfae5e61 /llvm/lib | |
| parent | a9abd62ede27930ea2b44951bc3a23663c2bf1f9 (diff) | |
| download | bcm5719-llvm-e974da6bb71d06405472468a4257099205685c32.tar.gz bcm5719-llvm-e974da6bb71d06405472468a4257099205685c32.zip | |
Speed up isCString()
llvm-svn: 31206
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index ce29a21f86c..9c92b907783 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/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; } |

