diff options
author | Chris Lattner <sabre@nondot.org> | 2007-02-12 18:52:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-02-12 18:52:59 +0000 |
commit | 1a5de584dca538300a570502be6c15942cc7d3cd (patch) | |
tree | f9424d81b1a76ae3569fbb4dcab4d3fc4d69abdd /llvm/lib | |
parent | 15f463c29146c59e8c1f87c400048a96c62244c1 (diff) | |
download | bcm5719-llvm-1a5de584dca538300a570502be6c15942cc7d3cd.tar.gz bcm5719-llvm-1a5de584dca538300a570502be6c15942cc7d3cd.zip |
Add new setName accessor which doesn't require creating a string.
llvm-svn: 34197
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/VMCore/Value.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp index 109994efb71..ee6f94ad386 100644 --- a/llvm/lib/VMCore/Value.cpp +++ b/llvm/lib/VMCore/Value.cpp @@ -119,33 +119,40 @@ std::string Value::getName() const { } void Value::setName(const std::string &name) { - if (name.empty() && !hasName()) return; + setName(&name[0], name.size()); +} + +void Value::setName(const char *NameStr, unsigned NameLen) { + if (NameLen == 0 && !hasName()) return; if (getType() != Type::VoidTy && "Cannot assign a name to void values!"); - // Get the symbol table to update for this object. ValueSymbolTable *ST; if (getSymTab(this, ST)) return; // Cannot set a name on this value (e.g. constant). if (!ST) { // No symbol table to update? Just do the change. - if (name.empty()) { + if (NameLen == 0) { // Free the name for this value. Name->Destroy(); Name = 0; - } else { - if (Name) { - // Name isn't changing. - if (name.size() == Name->getKeyLength() && - !memcmp(Name->getKeyData(), &name[0], name.size())) - return; - Name->Destroy(); - } - - // Create the new name. - Name = ValueName::Create(&name[0], &name[name.size()]); - Name->setValue(this); + return; } + + if (Name) { + // Name isn't changing? + if (NameLen == Name->getKeyLength() && + !memcmp(Name->getKeyData(), NameStr, NameLen)) + return; + Name->Destroy(); + } + + // NOTE: Could optimize for the case the name is shrinking to not deallocate + // then reallocated. + + // Create the new name. + Name = ValueName::Create(NameStr, NameStr+NameLen); + Name->setValue(this); return; } @@ -153,8 +160,8 @@ void Value::setName(const std::string &name) { // then reallocated. if (hasName()) { // Name isn't changing? - if (name.size() == Name->getKeyLength() && - !memcmp(Name->getKeyData(), &name[0], name.size())) + if (NameLen == Name->getKeyLength() && + !memcmp(Name->getKeyData(), NameStr, NameLen)) return; // Remove old name. @@ -162,14 +169,15 @@ void Value::setName(const std::string &name) { Name->Destroy(); Name = 0; - if (name.empty()) - return; + if (NameLen == 0) + return; } // Name is changing to something new. - Name = ST->createValueName(&name[0], name.size(), this); + Name = ST->createValueName(NameStr, NameLen, this); } + /// takeName - transfer the name from V to this value, setting V's name to /// empty. It is an error to call V->takeName(V). void Value::takeName(Value *V) { |