From 1e697f1348f2696a0a0f57f187b154d60a81289e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 15 Feb 2025 17:25:39 -0800 Subject: [PATCH] remove shared_ptr Because of make_shared, this is never NULL. Signed-off-by: Rosen Penev --- src/tiffcomposite_int.cpp | 10 +++++----- src/tiffcomposite_int.hpp | 8 ++++---- src/tiffvisitor_int.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 07c9a6c843..54231119b1 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -176,13 +176,13 @@ int TiffEntryBase::idx() const { return idx_; } -void TiffEntryBase::setData(std::shared_ptr buf) { +void TiffEntryBase::setData(DataBuf buf) { storage_ = std::move(buf); - pData_ = storage_->data(); - size_ = storage_->size(); + pData_ = storage_.data(); + size_ = storage_.size(); } -void TiffEntryBase::setData(byte* pData, size_t size, std::shared_ptr storage) { +void TiffEntryBase::setData(byte* pData, size_t size, DataBuf storage) { pData_ = pData; size_ = size; storage_ = std::move(storage); @@ -194,7 +194,7 @@ void TiffEntryBase::updateValue(Value::UniquePtr value, ByteOrder byteOrder) { if (!value) return; if (size_t newSize = value->size(); newSize > size_) { - auto d = std::make_shared(newSize); + auto d = DataBuf(newSize); setData(std::move(d)); } if (pData_) { diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index 0e28aba912..a56ee00350 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -428,13 +428,13 @@ class TiffEntryBase : public TiffComponent { you should pass std::shared_ptr(), which is essentially a nullptr. */ - void setData(byte* pData, size_t size, std::shared_ptr storage); + void setData(byte* pData, size_t size, DataBuf storage); /*! @brief Set the entry's data buffer. A shared_ptr is used to manage the DataBuf because TiffEntryBase has a clone method so it is possible (in theory) for the DataBuf to have multiple owners. */ - void setData(std::shared_ptr buf); + void setData(DataBuf buf); /*! @brief Update the value. Takes ownership of the pointer passed in. @@ -534,7 +534,7 @@ class TiffEntryBase : public TiffComponent { static size_t writeOffset(byte* buf, size_t offset, TiffType tiffType, ByteOrder byteOrder); //! Used (internally) to create another reference to the DataBuf reference by storage_. - [[nodiscard]] std::shared_ptr storage() const { + [[nodiscard]] DataBuf storage() const { return storage_; } @@ -559,7 +559,7 @@ class TiffEntryBase : public TiffComponent { // Otherwise, it remains empty. It is wrapped in a shared_ptr because // TiffEntryBase has a clone method, which could lead to the DataBuf // having multiple owners. - std::shared_ptr storage_; + DataBuf storage_; }; /*! diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 219cfe3bcb..eb9824cc82 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -1319,7 +1319,7 @@ void TiffReader::readTiffEntry(TiffEntryBase* object) { v->read(pData, size, byteOrder()); object->setValue(std::move(v)); - auto d = std::make_shared(); + DataBuf d; object->setData(pData, size, std::move(d)); object->setOffset(offset); object->setIdx(nextIdx(object->group())); @@ -1363,8 +1363,8 @@ void TiffReader::visitBinaryArray(TiffBinaryArray* object) { if (auto cryptFct = cfg->cryptFct_) { const byte* pData = object->pData(); size_t size = object->TiffEntryBase::doSize(); - auto buf = std::make_shared(cryptFct(object->tag(), pData, size, pRoot_)); - if (!buf->empty()) + auto buf = DataBuf(cryptFct(object->tag(), pData, size, pRoot_)); + if (!buf.empty()) object->setData(std::move(buf)); }