Avoid some unecessary heap allocations by using llvm's StringRef class.

This commit is contained in:
Benjamin Kramer
2009-08-14 01:43:30 +02:00
parent c220dcac05
commit d24643bb50
4 changed files with 73 additions and 74 deletions

View File

@@ -571,19 +571,19 @@ LLConstant* DtoConstFP(Type* t, long double value)
LLConstant* DtoConstString(const char* str)
{
std::string s(str?str:"");
llvm::StringRef s(str?str:"");
LLConstant* init = LLConstantArray::get(gIR->context(), s, true);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
*gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str");
LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
return DtoConstSlice(
DtoConstSize_t(s.length()),
DtoConstSize_t(s.size()),
llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2)
);
}
LLConstant* DtoConstStringPtr(const char* str, const char* section)
{
std::string s(str);
llvm::StringRef s(str);
LLConstant* init = LLConstantArray::get(gIR->context(), s, true);
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
*gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str");