diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-06-19 17:33:32 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-19 17:33:32 +0000 |
commit | e005dc33c31a2e701e1af3a0a3e5775cabbf1ddd (patch) | |
tree | 6cf7623219078464910ee438311e24121c8af2a0 /fxbarcode | |
parent | ed1c58049f0c164969946b6ad0ff06d952ab1949 (diff) | |
download | pdfium-e005dc33c31a2e701e1af3a0a3e5775cabbf1ddd.tar.xz |
Move fxcrt::{Byte,Wide}Strings with std::move().chromium/3466
Remove some string copies in barcode that were noticed whilst
looking for moves.
Change-Id: Ieda34d00f633576ba1f0dca283dcdabfb36f236c
Reviewed-on: https://pdfium-review.googlesource.com/35410
Reviewed-by: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxbarcode')
-rw-r--r-- | fxbarcode/cbc_codabar.cpp | 12 | ||||
-rw-r--r-- | fxbarcode/cbc_code128.cpp | 11 | ||||
-rw-r--r-- | fxbarcode/cbc_code39.cpp | 9 | ||||
-rw-r--r-- | fxbarcode/cbc_ean13.cpp | 11 | ||||
-rw-r--r-- | fxbarcode/cbc_ean8.cpp | 11 | ||||
-rw-r--r-- | fxbarcode/cbc_upca.cpp | 12 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_DefaultPlacement.cpp | 12 | ||||
-rw-r--r-- | fxbarcode/datamatrix/BC_EncoderContext.cpp | 4 |
8 files changed, 34 insertions, 48 deletions
diff --git a/fxbarcode/cbc_codabar.cpp b/fxbarcode/cbc_codabar.cpp index 0795ff295d..b32eafc376 100644 --- a/fxbarcode/cbc_codabar.cpp +++ b/fxbarcode/cbc_codabar.cpp @@ -54,17 +54,13 @@ bool CBC_Codabar::Encode(const WideStringView& contents) { BCFORMAT format = BCFORMAT_CODABAR; int32_t outWidth = 0; int32_t outHeight = 0; - WideString filtercontents = GetOnedCodaBarWriter()->FilterContents(contents); - ByteString byteString = filtercontents.UTF8Encode(); - m_renderContents = filtercontents; + m_renderContents = GetOnedCodaBarWriter()->FilterContents(contents); + ByteString byteString = m_renderContents.UTF8Encode(); auto* pWriter = GetOnedCodaBarWriter(); std::unique_ptr<uint8_t, FxFreeDeleter> data( pWriter->Encode(byteString, format, outWidth, outHeight)); - if (!data) - return false; - - return pWriter->RenderResult(filtercontents.AsStringView(), data.get(), - outWidth); + return data && pWriter->RenderResult(m_renderContents.AsStringView(), + data.get(), outWidth); } bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device, diff --git a/fxbarcode/cbc_code128.cpp b/fxbarcode/cbc_code128.cpp index 7ba623542d..8e83e2251c 100644 --- a/fxbarcode/cbc_code128.cpp +++ b/fxbarcode/cbc_code128.cpp @@ -47,15 +47,12 @@ bool CBC_Code128::Encode(const WideStringView& contents) { if (contents.GetLength() % 2 && pWriter->GetType() == BC_CODE128_C) content += '0'; - WideString encodeContents = pWriter->FilterContents(content.AsStringView()); - m_renderContents = encodeContents; - ByteString byteString = encodeContents.UTF8Encode(); + m_renderContents = pWriter->FilterContents(content.AsStringView()); + ByteString byteString = m_renderContents.UTF8Encode(); std::unique_ptr<uint8_t, FxFreeDeleter> data( pWriter->Encode(byteString, format, outWidth, outHeight)); - if (!data) - return false; - return pWriter->RenderResult(encodeContents.AsStringView(), data.get(), - outWidth); + return data && pWriter->RenderResult(m_renderContents.AsStringView(), + data.get(), outWidth); } bool CBC_Code128::RenderDevice(CFX_RenderDevice* device, diff --git a/fxbarcode/cbc_code39.cpp b/fxbarcode/cbc_code39.cpp index 9715c25828..52859e14c5 100644 --- a/fxbarcode/cbc_code39.cpp +++ b/fxbarcode/cbc_code39.cpp @@ -40,15 +40,12 @@ bool CBC_Code39::Encode(const WideStringView& contents) { int32_t outHeight = 0; auto* pWriter = GetOnedCode39Writer(); WideString filtercontents = pWriter->FilterContents(contents); - WideString renderContents = pWriter->RenderTextContents(contents); - m_renderContents = renderContents; + m_renderContents = pWriter->RenderTextContents(contents); ByteString byteString = filtercontents.UTF8Encode(); std::unique_ptr<uint8_t, FxFreeDeleter> data( pWriter->Encode(byteString, format, outWidth, outHeight)); - if (!data) - return false; - return pWriter->RenderResult(renderContents.AsStringView(), data.get(), - outWidth); + return data && pWriter->RenderResult(m_renderContents.AsStringView(), + data.get(), outWidth); } bool CBC_Code39::RenderDevice(CFX_RenderDevice* device, diff --git a/fxbarcode/cbc_ean13.cpp b/fxbarcode/cbc_ean13.cpp index 16725323f4..a111fdbfb6 100644 --- a/fxbarcode/cbc_ean13.cpp +++ b/fxbarcode/cbc_ean13.cpp @@ -57,16 +57,13 @@ bool CBC_EAN13::Encode(const WideStringView& contents) { BCFORMAT format = BCFORMAT_EAN_13; int32_t outWidth = 0; int32_t outHeight = 0; - WideString encodeContents = Preprocess(contents); - ByteString byteString = encodeContents.UTF8Encode(); - m_renderContents = encodeContents; + m_renderContents = Preprocess(contents); + ByteString byteString = m_renderContents.UTF8Encode(); auto* pWriter = GetOnedEAN13Writer(); std::unique_ptr<uint8_t, FxFreeDeleter> data( pWriter->Encode(byteString, format, outWidth, outHeight)); - if (!data) - return false; - return pWriter->RenderResult(encodeContents.AsStringView(), data.get(), - outWidth); + return data && pWriter->RenderResult(m_renderContents.AsStringView(), + data.get(), outWidth); } bool CBC_EAN13::RenderDevice(CFX_RenderDevice* device, diff --git a/fxbarcode/cbc_ean8.cpp b/fxbarcode/cbc_ean8.cpp index 796f3a526b..ce071af2ce 100644 --- a/fxbarcode/cbc_ean8.cpp +++ b/fxbarcode/cbc_ean8.cpp @@ -55,16 +55,13 @@ bool CBC_EAN8::Encode(const WideStringView& contents) { BCFORMAT format = BCFORMAT_EAN_8; int32_t outWidth = 0; int32_t outHeight = 0; - WideString encodeContents = Preprocess(contents); - ByteString byteString = encodeContents.UTF8Encode(); - m_renderContents = encodeContents; + m_renderContents = Preprocess(contents); + ByteString byteString = m_renderContents.UTF8Encode(); auto* pWriter = GetOnedEAN8Writer(); std::unique_ptr<uint8_t, FxFreeDeleter> data( pWriter->Encode(byteString, format, outWidth, outHeight)); - if (!data) - return false; - return pWriter->RenderResult(encodeContents.AsStringView(), data.get(), - outWidth); + return data && pWriter->RenderResult(m_renderContents.AsStringView(), + data.get(), outWidth); } bool CBC_EAN8::RenderDevice(CFX_RenderDevice* device, diff --git a/fxbarcode/cbc_upca.cpp b/fxbarcode/cbc_upca.cpp index 69cedce580..834eecf1ec 100644 --- a/fxbarcode/cbc_upca.cpp +++ b/fxbarcode/cbc_upca.cpp @@ -56,18 +56,14 @@ bool CBC_UPCA::Encode(const WideStringView& contents) { BCFORMAT format = BCFORMAT_UPC_A; int32_t outWidth = 0; int32_t outHeight = 0; - WideString encodeContents = Preprocess(contents); - ByteString byteString = encodeContents.UTF8Encode(); - m_renderContents = encodeContents; - + m_renderContents = Preprocess(contents); + ByteString byteString = m_renderContents.UTF8Encode(); CBC_OnedUPCAWriter* pWriter = GetOnedUPCAWriter(); pWriter->Init(); std::unique_ptr<uint8_t, FxFreeDeleter> data( pWriter->Encode(byteString, format, outWidth, outHeight)); - if (!data) - return false; - return pWriter->RenderResult(encodeContents.AsStringView(), data.get(), - outWidth); + return data && pWriter->RenderResult(m_renderContents.AsStringView(), + data.get(), outWidth); } bool CBC_UPCA::RenderDevice(CFX_RenderDevice* device, diff --git a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp index 3f1b35864f..24d81f1bb3 100644 --- a/fxbarcode/datamatrix/BC_DefaultPlacement.cpp +++ b/fxbarcode/datamatrix/BC_DefaultPlacement.cpp @@ -21,19 +21,23 @@ */ #include "fxbarcode/datamatrix/BC_DefaultPlacement.h" + +#include <utility> + #include "fxbarcode/datamatrix/BC_Encoder.h" CBC_DefaultPlacement::CBC_DefaultPlacement(WideString codewords, int32_t numcols, - int32_t numrows) { - m_codewords = codewords; - m_numcols = numcols; - m_numrows = numrows; + int32_t numrows) + : m_codewords(std::move(codewords)), + m_numrows(numrows), + m_numcols(numcols) { m_bits.resize(numcols * numrows); for (int32_t i = 0; i < numcols * numrows; i++) { m_bits[i] = (uint8_t)2; } } + CBC_DefaultPlacement::~CBC_DefaultPlacement() {} int32_t CBC_DefaultPlacement::getNumrows() { diff --git a/fxbarcode/datamatrix/BC_EncoderContext.cpp b/fxbarcode/datamatrix/BC_EncoderContext.cpp index f5c2f4c1fc..e72d1e4640 100644 --- a/fxbarcode/datamatrix/BC_EncoderContext.cpp +++ b/fxbarcode/datamatrix/BC_EncoderContext.cpp @@ -22,6 +22,8 @@ #include "fxbarcode/datamatrix/BC_EncoderContext.h" +#include <utility> + #include "fxbarcode/BC_UtilCodingConvert.h" #include "fxbarcode/common/BC_CommonBitMatrix.h" #include "fxbarcode/datamatrix/BC_Encoder.h" @@ -43,7 +45,7 @@ CBC_EncoderContext::CBC_EncoderContext(const WideString& msg, } sb += ch; } - m_msg = sb; + m_msg = std::move(sb); m_codewords.Reserve(m_msg.GetLength()); m_allowRectangular = true; m_newEncoding = -1; |