Skip to content

Commit

Permalink
remove shared_ptr
Browse files Browse the repository at this point in the history
Because of make_shared, this is never NULL.

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Feb 16, 2025
1 parent ecfb739 commit 1e697f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ int TiffEntryBase::idx() const {
return idx_;
}

void TiffEntryBase::setData(std::shared_ptr<DataBuf> 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<DataBuf> storage) {
void TiffEntryBase::setData(byte* pData, size_t size, DataBuf storage) {
pData_ = pData;
size_ = size;
storage_ = std::move(storage);
Expand All @@ -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<DataBuf>(newSize);
auto d = DataBuf(newSize);
setData(std::move(d));
}
if (pData_) {
Expand Down
8 changes: 4 additions & 4 deletions src/tiffcomposite_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ class TiffEntryBase : public TiffComponent {
you should pass std::shared_ptr<DataBuf>(), which is essentially
a nullptr.
*/
void setData(byte* pData, size_t size, std::shared_ptr<DataBuf> 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<DataBuf> buf);
void setData(DataBuf buf);
/*!
@brief Update the value. Takes ownership of the pointer passed in.
Expand Down Expand Up @@ -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<DataBuf> storage() const {
[[nodiscard]] DataBuf storage() const {
return storage_;
}

Expand All @@ -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<DataBuf> storage_;
DataBuf storage_;
};

/*!
Expand Down
6 changes: 3 additions & 3 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
DataBuf d;
object->setData(pData, size, std::move(d));
object->setOffset(offset);
object->setIdx(nextIdx(object->group()));
Expand Down Expand Up @@ -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<DataBuf>(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));
}

Expand Down

0 comments on commit 1e697f1

Please sign in to comment.