From 1e934f6868465bca960f9f13489489ba1d649581 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 11 Apr 2018 21:11:28 +0000 Subject: Remove use of GetBuffer()/ReleaseBuffer() when c_str() is sufficient. Greatly simplify the code which was neither changing allocations nor doing any actual work. Eventually GetBuffer() will return a span, and this makes fewer places to change. Comment AsFPDFWideString() as a place where we may want a redundant copy, and make available outside the .cpp file. Fix one "const" along the way. Change-Id: I187758b69a0ba3501b3622f6c06280793cd5d464 Reviewed-on: https://pdfium-review.googlesource.com/30011 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fpdfsdk/fpdf_text.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'fpdfsdk/fpdf_text.cpp') diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp index 7778696931..c5906acef0 100644 --- a/fpdfsdk/fpdf_text.cpp +++ b/fpdfsdk/fpdf_text.cpp @@ -193,7 +193,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetText(FPDF_TEXTPAGE page, int ret_count = byte_str_len / kBytesPerCharacter; ASSERT(ret_count <= char_count + 1); // +1 to account for the NUL terminator. - memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len); + memcpy(result, byte_str.c_str(), byte_str_len); return ret_count; } @@ -247,8 +247,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page, ByteString cbUTF16Str = str.UTF16LE_Encode(); int len = cbUTF16Str.GetLength() / sizeof(unsigned short); int size = buflen > len ? len : buflen; - memcpy(buffer, cbUTF16Str.GetBuffer(size * sizeof(unsigned short)), - size * sizeof(unsigned short)); + memcpy(buffer, cbUTF16Str.c_str(), size * sizeof(unsigned short)); cbUTF16Str.ReleaseBuffer(size * sizeof(unsigned short)); return size; @@ -352,7 +351,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFLink_GetURL(FPDF_PAGELINK link_page, int size = std::min(required, buflen); if (size > 0) { int buf_size = size * sizeof(unsigned short); - memcpy(buffer, cbUTF16URL.GetBuffer(buf_size), buf_size); + memcpy(buffer, cbUTF16URL.c_str(), buf_size); } return size; } -- cgit v1.2.3