Mercurial > projects > ldc
comparison gen/tollvm.cpp @ 1572:30bdcfb8299e
Avoid some unecessary heap allocations by using llvm's StringRef class.
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Fri, 14 Aug 2009 01:43:30 +0200 |
parents | 8d086d552909 |
children | e4f7b5d9c68a |
comparison
equal
deleted
inserted
replaced
1571:8d086d552909 | 1572:30bdcfb8299e |
---|---|
569 | 569 |
570 ////////////////////////////////////////////////////////////////////////////////////////// | 570 ////////////////////////////////////////////////////////////////////////////////////////// |
571 | 571 |
572 LLConstant* DtoConstString(const char* str) | 572 LLConstant* DtoConstString(const char* str) |
573 { | 573 { |
574 std::string s(str?str:""); | 574 llvm::StringRef s(str?str:""); |
575 LLConstant* init = LLConstantArray::get(gIR->context(), s, true); | 575 LLConstant* init = LLConstantArray::get(gIR->context(), s, true); |
576 llvm::GlobalVariable* gvar = new llvm::GlobalVariable( | 576 llvm::GlobalVariable* gvar = new llvm::GlobalVariable( |
577 *gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str"); | 577 *gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str"); |
578 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; | 578 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
579 return DtoConstSlice( | 579 return DtoConstSlice( |
580 DtoConstSize_t(s.length()), | 580 DtoConstSize_t(s.size()), |
581 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2) | 581 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2) |
582 ); | 582 ); |
583 } | 583 } |
584 LLConstant* DtoConstStringPtr(const char* str, const char* section) | 584 LLConstant* DtoConstStringPtr(const char* str, const char* section) |
585 { | 585 { |
586 std::string s(str); | 586 llvm::StringRef s(str); |
587 LLConstant* init = LLConstantArray::get(gIR->context(), s, true); | 587 LLConstant* init = LLConstantArray::get(gIR->context(), s, true); |
588 llvm::GlobalVariable* gvar = new llvm::GlobalVariable( | 588 llvm::GlobalVariable* gvar = new llvm::GlobalVariable( |
589 *gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str"); | 589 *gIR->module, init->getType(), true,llvm::GlobalValue::InternalLinkage, init, ".str"); |
590 if (section) gvar->setSection(section); | 590 if (section) gvar->setSection(section); |
591 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; | 591 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |