This is a combination of running clang-tidy with modernize-use-nullptr check for some ports (GTK, X11, OSX) and manual changes to the ports for which it couldn't be used easily (MSW, DFB) and also manually updating the docs. Also replace NULL with null or nullptr in the comments as this is more consistent with the use of nullptr in the code and makes it simpler to grep for the remaining occurrences of NULL itself. And also use null in the assert messages. Only a few occurrences of "NULL" are still left in non-C files, mostly corresponding to unclear comments or string output which it might not be safe to change.
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: tests/benchmarks/mbconv.cpp
|
|
// Purpose: MB<->WC conversion benchmarks
|
|
// Author: Vadim Zeitlin
|
|
// Created: 2008-10-17
|
|
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
// Licence: wxWindows licence
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "wx/strconv.h"
|
|
#include "wx/string.h"
|
|
|
|
#include "bench.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
const wchar_t *TEST_STRING =
|
|
L"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod"
|
|
L"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim"
|
|
L"veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"
|
|
L"commodo consequat. Duis aute irure dolor in reprehenderit in voluptate"
|
|
L"velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint"
|
|
L"occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
|
|
L"mollit anim id est laborum."
|
|
;
|
|
|
|
// just compute the length of the resulting multibyte string
|
|
bool ComputeMBLength(const wxMBConv& conv)
|
|
{
|
|
// we suppose a fixed length encoding here (which happens to cover UTF-8
|
|
// too as long as the test string is ASCII)
|
|
return conv.FromWChar(nullptr, 0, TEST_STRING)
|
|
== (wcslen(TEST_STRING) + 1)*conv.GetMBNulLen();
|
|
}
|
|
|
|
// perform the conversion
|
|
bool ConvertToMB(const wxMBConv& conv)
|
|
{
|
|
const size_t outlen = (wcslen(TEST_STRING) + 1)*conv.GetMBNulLen();
|
|
wxCharBuffer buf(outlen - 1); // it adds 1 internally
|
|
return conv.FromWChar(buf.data(), outlen, TEST_STRING) == outlen;
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
BENCHMARK_FUNC(UTF16InitWX)
|
|
{
|
|
wxMBConvUTF16 conv;
|
|
return true;
|
|
}
|
|
|
|
BENCHMARK_FUNC(UTF16InitSys)
|
|
{
|
|
wxCSConv conv("UTF-16LE");
|
|
return conv.IsOk();
|
|
}
|
|
|
|
BENCHMARK_FUNC(UTF16LenWX)
|
|
{
|
|
return ComputeMBLength(wxMBConvUTF16());
|
|
}
|
|
|
|
BENCHMARK_FUNC(UTF16LenSys)
|
|
{
|
|
return ComputeMBLength(wxCSConv("UTF-16LE"));
|
|
}
|
|
|
|
BENCHMARK_FUNC(UTF16WX)
|
|
{
|
|
return ConvertToMB(wxMBConvUTF16());
|
|
}
|
|
|
|
BENCHMARK_FUNC(UTF16Sys)
|
|
{
|
|
return ConvertToMB(wxCSConv("UTF-16LE"));
|
|
}
|
|
|