Revert "Delete STACK_ARRAY macro, and use of alloca"
This reverts commit 74b373f04a69b279e45b0792d86c594cb33d22c1.
Reason for revert: This breaks chromium, blocking webrtc from rolling.
...
In file included from ../../third_party/webrtc\rtc_base/strings/string_builder.h:23:
../../third_party/webrtc\rtc_base/string_utils.h(54,28): error: implicit conversion loses integer precision: 'std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::size_type' (aka 'unsigned long long') to 'int' [-Werror,-Wshorten-64-to-32]
ws.size());
See https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8912652299012991936/+/steps/compile__with_patch_/0/stdout
Original change's description:
> Delete STACK_ARRAY macro, and use of alloca
>
> Refactor the few uses of STACK_ARRAY to avoid an extra copy
> on the stack.
>
> Bug: webrtc:6424
> Change-Id: I5c8f3c0381523db0ead31207d949df9a286c76ba
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137806
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#28038}
TBR=kwiberg@webrtc.org,nisse@webrtc.org
Change-Id: I223fceab60855dde363cc9ce8375e8f5cca43c02
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:6424
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/138209
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28043}
This commit is contained in:
committed by
Commit Bot
parent
2988acac05
commit
c1b36669db
@ -21,15 +21,31 @@
|
||||
#include <wchar.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define alloca _alloca
|
||||
#endif // WEBRTC_WIN
|
||||
|
||||
#if defined(WEBRTC_POSIX)
|
||||
#ifdef BSD
|
||||
#include <stdlib.h>
|
||||
#else // BSD
|
||||
#include <alloca.h>
|
||||
#endif // !BSD
|
||||
#include <strings.h>
|
||||
#endif // WEBRTC_POSIX
|
||||
|
||||
#include <string>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Generic string/memory utilities
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define STACK_ARRAY(TYPE, LEN) \
|
||||
static_cast<TYPE*>(::alloca((LEN) * sizeof(TYPE)))
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Traits simplifies porting string functions to be CTYPE-agnostic
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace rtc {
|
||||
|
||||
const size_t SIZE_UNKNOWN = static_cast<size_t>(-1);
|
||||
@ -49,10 +65,9 @@ size_t strcpyn(char* buffer,
|
||||
inline std::wstring ToUtf16(const char* utf8, size_t len) {
|
||||
int len16 = ::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len),
|
||||
nullptr, 0);
|
||||
std::wstring ws(len16, 0);
|
||||
::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len), &*ws.begin(),
|
||||
ws.size());
|
||||
return ws;
|
||||
wchar_t* ws = STACK_ARRAY(wchar_t, len16);
|
||||
::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len), ws, len16);
|
||||
return std::wstring(ws, len16);
|
||||
}
|
||||
|
||||
inline std::wstring ToUtf16(const std::string& str) {
|
||||
@ -62,10 +77,10 @@ inline std::wstring ToUtf16(const std::string& str) {
|
||||
inline std::string ToUtf8(const wchar_t* wide, size_t len) {
|
||||
int len8 = ::WideCharToMultiByte(CP_UTF8, 0, wide, static_cast<int>(len),
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
std::string ns(len8, 0);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wide, static_cast<int>(len), &*ns.begin(),
|
||||
ns.size(), nullptr, nullptr);
|
||||
return ns;
|
||||
char* ns = STACK_ARRAY(char, len8);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wide, static_cast<int>(len), ns, len8,
|
||||
nullptr, nullptr);
|
||||
return std::string(ns, len8);
|
||||
}
|
||||
|
||||
inline std::string ToUtf8(const wchar_t* wide) {
|
||||
|
||||
Reference in New Issue
Block a user