[llvm] r192137 - Windows: Avoiding resizing, use uninitialized data() instead
David Majnemer
david.majnemer at gmail.com
Mon Oct 7 14:57:07 PDT 2013
Author: majnemer
Date: Mon Oct 7 16:57:07 2013
New Revision: 192137
URL: http://llvm.org/viewvc/llvm-project?rev=192137&view=rev
Log:
Windows: Avoiding resizing, use uninitialized data() instead
This is ever-so faster but more importantly matches what we have elsewhere.
Modified:
llvm/trunk/lib/Support/Windows/Process.inc
Modified: llvm/trunk/lib/Support/Windows/Process.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Process.inc?rev=192137&r1=192136&r2=192137&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Process.inc (original)
+++ llvm/trunk/lib/Support/Windows/Process.inc Mon Oct 7 16:57:07 2013
@@ -161,8 +161,9 @@ Optional<std::string> Process::GetEnv(St
SmallVector<wchar_t, MAX_PATH> Buf;
size_t Size = MAX_PATH;
do {
- Buf.resize(Size);
- Size = GetEnvironmentVariableW(&NameUTF16[0], &Buf[0], Buf.capacity());
+ Buf.reserve(Size);
+ Size =
+ GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.capacity());
if (Size == 0)
return None;
@@ -172,9 +173,9 @@ Optional<std::string> Process::GetEnv(St
// Convert the result from UTF-16 to UTF-8.
SmallVector<char, MAX_PATH> Res;
- if (error_code ec = windows::UTF16ToUTF8(&Buf[0], Size, Res))
+ if (error_code ec = windows::UTF16ToUTF8(Buf.data(), Size, Res))
return None;
- return std::string(&Res[0]);
+ return std::string(Res.data());
}
error_code
More information about the llvm-commits
mailing list