Revert "Use DataVector in CFX_MemoryStream."
This reverts commit a015667fdd1157552c9b652d959322d89d5cd179.
Reason for revert: So pdfium-review.googlesource.com/97691 reverts
cleanly
Original change's description:
> Use DataVector in CFX_MemoryStream.
>
> Bug: pdfium:1872
> Change-Id: I67eef8a307fe6375154939b68bc3b25c51759fc1
> Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/97710
> Commit-Queue: Lei Zhang <thestig@chromium.org>
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: pdfium:1872
Change-Id: I6fcb02e3e8caa9181c95f18892019efaafd0711c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/97852
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/cfx_memorystream.cpp b/core/fxcrt/cfx_memorystream.cpp
index 28551ca..9c89bc7 100644
--- a/core/fxcrt/cfx_memorystream.cpp
+++ b/core/fxcrt/cfx_memorystream.cpp
@@ -10,7 +10,6 @@
#include <utility>
#include "core/fxcrt/fx_safe_types.h"
-#include "core/fxcrt/span_util.h"
CFX_MemoryStream::CFX_MemoryStream() = default;
@@ -73,7 +72,7 @@
return false;
size_t new_pos = safe_new_pos.ValueOrDie();
- if (new_pos > m_data.size()) {
+ if (new_pos > m_nTotalSize) {
static constexpr size_t kBlockSize = 64 * 1024;
FX_SAFE_SIZE_T new_size = new_pos;
new_size *= 2;
@@ -83,12 +82,15 @@
if (!new_size.IsValid())
return false;
- m_data.resize(new_size.ValueOrDie());
+ m_nTotalSize = new_size.ValueOrDie();
+ if (m_data)
+ m_data.reset(FX_Realloc(uint8_t, m_data.release(), m_nTotalSize));
+ else
+ m_data.reset(FX_Alloc(uint8_t, m_nTotalSize));
}
m_nCurPos = new_pos;
- fxcrt::spancpy(pdfium::make_span(m_data),
- pdfium::make_span(static_cast<const uint8_t*>(buffer), size));
+ memcpy(&m_data.get()[offset], buffer, size);
m_nCurSize = std::max(m_nCurSize, m_nCurPos);
return true;
diff --git a/core/fxcrt/cfx_memorystream.h b/core/fxcrt/cfx_memorystream.h
index a573a60..f72a211 100644
--- a/core/fxcrt/cfx_memorystream.h
+++ b/core/fxcrt/cfx_memorystream.h
@@ -7,7 +7,9 @@
#ifndef CORE_FXCRT_CFX_MEMORYSTREAM_H_
#define CORE_FXCRT_CFX_MEMORYSTREAM_H_
-#include "core/fxcrt/data_vector.h"
+#include <memory>
+
+#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/retain_ptr.h"
@@ -28,13 +30,14 @@
size_t size) override;
bool Flush() override;
- const uint8_t* GetBuffer() const { return m_data.data(); }
+ const uint8_t* GetBuffer() const { return m_data.get(); }
private:
CFX_MemoryStream();
~CFX_MemoryStream() override;
- DataVector<uint8_t> m_data;
+ std::unique_ptr<uint8_t, FxFreeDeleter> m_data;
+ size_t m_nTotalSize = 0;
size_t m_nCurSize = 0;
size_t m_nCurPos = 0;
};