1 //===- StringEntry.cpp ----------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include "mcld/ADT/StringEntry.h" 10 11 namespace mcld { 12 13 //===----------------------------------------------------------------------===// 14 // StringEntry<llvm::StringRef> 15 //===----------------------------------------------------------------------===// StringEntry()16StringEntry<llvm::StringRef>::StringEntry() { 17 } 18 StringEntry(const StringEntry::key_type & pKey)19StringEntry<llvm::StringRef>::StringEntry(const StringEntry::key_type& pKey) { 20 } 21 StringEntry(const StringEntry<llvm::StringRef> & pCopy)22StringEntry<llvm::StringRef>::StringEntry( 23 const StringEntry<llvm::StringRef>& pCopy) { 24 assert("Copy constructor of StringEntry should not be called!"); 25 } 26 ~StringEntry()27StringEntry<llvm::StringRef>::~StringEntry() { 28 if (!m_Value.empty()) 29 free(const_cast<char*>(m_Value.data())); 30 } 31 setValue(llvm::StringRef pVal)32void StringEntry<llvm::StringRef>::setValue(llvm::StringRef pVal) { 33 char* data = reinterpret_cast<char*>(malloc(pVal.size() + 1)); 34 ::memcpy(data, pVal.data(), pVal.size()); 35 m_Value = llvm::StringRef(data, pVal.size()); 36 } 37 setValue(const char * pVal)38void StringEntry<llvm::StringRef>::setValue(const char* pVal) { 39 size_t length = strlen(pVal); 40 char* data = reinterpret_cast<char*>(malloc(length + 1)); 41 ::memcpy(data, pVal, length); 42 m_Value = llvm::StringRef(data, length); 43 } 44 45 } // namespace mcld 46