From 9b0a5ee5bb77b5f74320f3603750f4521d16d196 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 14 Jan 2004 17:06:21 +0000 Subject: [PATCH] Add new ConstantArray::isString(), as the conditions for using getString() are complex enough to check that it should be a seperate method. While I'm here, improve ConstantArray::getNullValue a bit, though the FIXME is still quite valid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10850 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constants.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 36969d9fabe..8d0ec281f89 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -304,9 +304,12 @@ public: return reinterpret_cast(Value::getType()); } - /// getAsString - If the sub-element type of this array is either sbyte or - /// ubyte, then this method converts the array to an std::string and returns - /// it. Otherwise, it asserts out. + /// isString - This method returns true if the array is an array of sbyte or + /// ubyte, and if the elements of the array are all ConstantInt's. + bool isString() const; + + /// getAsString - If this array is isString(), then this method converts the + /// array to an std::string and returns it. Otherwise, it asserts out. /// std::string getAsString() const; @@ -319,9 +322,13 @@ public: virtual bool isNullValue() const { // FIXME: This should be made to be MUCH faster. Just check against well // known null value! - for (unsigned i = 0, e = getNumOperands(); i != e; ++i) - if (!cast(getOperand(i))->isNullValue()) - return false; + if (getNumOperands()) { + const Constant *First = cast(getOperand(0)); + if (!First->isNullValue()) return false; + for (unsigned i = 1, e = getNumOperands(); i != e; ++i) + if (cast(getOperand(i)) != First) + return false; + } return true; }