[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp
Evan Cheng
evan.cheng at apple.com
Thu Oct 26 14:48:22 PDT 2006
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.167 -> 1.168
---
Log message:
Speed up isCString()
---
Diffs of the changes: (+14 -4)
Constants.cpp | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.167 llvm/lib/VMCore/Constants.cpp:1.168
--- llvm/lib/VMCore/Constants.cpp:1.167 Thu Oct 26 14:15:05 2006
+++ llvm/lib/VMCore/Constants.cpp Thu Oct 26 16:48:03 2006
@@ -1077,11 +1077,21 @@
/// 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;
}
More information about the llvm-commits
mailing list