From 2cf0d21788974dd1ea19a68259c4fbccb0e56897 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 5 May 2015 15:15:38 -0700 Subject: Make sure string constructors are efficient on literals Separate out the overload when the length is not known, and be sure that strlen() call is in the header so that strlen("foo") => 3 (since many compilers support this optimization). Also delete some unused types. BUG=pdfium:151 R=thestig@chromium.org Review URL: https://codereview.chromium.org/1117263004 --- core/src/fxcrt/fx_basic_wstring.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'core/src') diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp index 9b27537ed9..3465b4a926 100644 --- a/core/src/fxcrt/fx_basic_wstring.cpp +++ b/core/src/fxcrt/fx_basic_wstring.cpp @@ -63,21 +63,6 @@ CFX_WideString::~CFX_WideString() FX_Free(m_pData); } } -void CFX_WideString::InitStr(FX_LPCWSTR lpsz, FX_STRSIZE nLen) -{ - if (nLen < 0) { - nLen = lpsz ? (FX_STRSIZE)FXSYS_wcslen(lpsz) : 0; - } - if (nLen) { - m_pData = FX_AllocStringW(nLen); - if (!m_pData) { - return; - } - FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR)); - } else { - m_pData = NULL; - } -} CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) { if (stringSrc.m_pData == NULL) { @@ -92,6 +77,19 @@ CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) *this = stringSrc; } } +CFX_WideString::CFX_WideString(FX_LPCWSTR lpsz, FX_STRSIZE nLen) { + if (nLen < 0) { + nLen = lpsz ? (FX_STRSIZE)FXSYS_wcslen(lpsz) : 0; + } + if (nLen) { + m_pData = FX_AllocStringW(nLen); + if (m_pData) { + FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR)); + } + } else { + m_pData = NULL; + } +} CFX_WideString::CFX_WideString(FX_WCHAR ch) { m_pData = FX_AllocStringW(1); -- cgit v1.2.3