[llvm-dev] Redundant Twine->StringRef->Twine conversions in llvm::sys::fs::make_absolute?
<Alexander G. Riccio> via llvm-dev
llvm-dev at lists.llvm.org
Mon Apr 18 14:55:34 PDT 2016
llvm::sys::fs::make_absolute converts its first parameter (const Twine
¤t_directory) to StringRef p(path.data(), path.size()), and then
passes that StringRef to several functions (path::has_root_directory,
path::has_root_name, and path::append) that accept Twines as parameters.
Since llvm::StringRef can implicitly convert to an llvm::Twine, p converts
to a bunch of Twine temporaries.
In a few places, namely path::has_root_directory & path::has_root_name,
that temporary Twine is again converted to a StringRef:
bool has_root_directory(const Twine &path) {
SmallString<128> path_storage;
StringRef p = path.toStringRef(path_storage);
return !root_directory(p).empty();
}
Is there some reason for this? If not, I'll write a patch to delay the
StringRef
p(path.data(), path.size()) construction until it's actually needed (calls
to path::root_name(p) & path::relative_path(p)).
Sincerely,
Alexander Riccio
--
"Change the world or go home."
about.me/ariccio
<http://about.me/ariccio>
If left to my own devices, I will build more.
⁂
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160418/8762dc8b/attachment.html>
More information about the llvm-dev
mailing list