Skip to content

Conversation

@N-Dekker
Copy link
Contributor

Simplified the class by removing its member variables m_DeleteIStream and m_WasmStringStream. Avoided manual memory management.

@N-Dekker N-Dekker force-pushed the InputStreamBase-unique_ptr-istream branch from 14ff273 to f3ed77f Compare July 23, 2025 19:04
N-Dekker added 2 commits July 24, 2025 11:44
Simplified the class by removing its member variables m_DeleteIStream and
m_WasmStringStream. Avoided manual memory management.
Moved the implementation of non-trivial member functions of InputStreamBase
(including its defaulted destructor, which deallocates dynamic memory) from its
h file to its cxx file. Might improve the compilation speed.
@N-Dekker N-Dekker force-pushed the InputStreamBase-unique_ptr-istream branch from f3ed77f to 965f201 Compare July 24, 2025 09:44
@N-Dekker N-Dekker marked this pull request as ready for review July 24, 2025 12:23
@thewtex thewtex requested a review from Copilot July 25, 2025 00:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the InputStreamBase class by replacing manual memory management with std::unique_ptr<std::istream>, eliminating the need for manual cleanup and simplifying the class design.

Key changes:

  • Replaced raw pointer m_IStream with std::unique_ptr<std::istream>
  • Removed manual memory management variables m_DeleteIStream and m_WasmStringStream
  • Moved method implementations from header to source file

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
include/itkInputStreamBase.h Replaced raw pointer with unique_ptr, removed manual memory management members, moved method declarations
src/itkInputStreamBase.cxx Added method implementations using unique_ptr and modern C++ practices

{
const auto wasmStringStream = WasmStringStream::New();
wasmStringStream->SetJSON(json.c_str());
m_IStream = std::make_unique<std::stringstream>(std::move(wasmStringStream->GetStringStream()));
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line attempts to move-construct a stringstream from another stringstream, but the GetStringStream() method likely returns a reference, not a movable object. This could result in compilation errors or unintended copying. Consider using a different approach to transfer the stream data.

Suggested change
m_IStream = std::make_unique<std::stringstream>(std::move(wasmStringStream->GetStringStream()));
std::stringstream tempStream = wasmStringStream->GetStringStream();
m_IStream = std::make_unique<std::stringstream>(tempStream.str());

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change suggested by Copilot does not compile. Specifically:

    std::stringstream tempStream = wasmStringStream->GetStringStream();

This suggestion would try to copy-construct a std::stringstream, but std::stringstream is not copy-constructible!

std::stringstream is move-construcible, so the stringstream of a WasmStringStream object can be properly moved into another stringstream, as in the proposed PR. Especially because the WasmStringStream object itself is no longer used afterwards.

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker thanks!

@thewtex thewtex merged commit 323d263 into InsightSoftwareConsortium:main Jul 25, 2025
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants