Skip to content

Commit

Permalink
Make buffer manager context getter return a mutable reference.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 720347065
  • Loading branch information
LukeBoyer authored and tensorflower-gardener committed Jan 28, 2025
1 parent ed6f659 commit 799ada6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cstddef>
#include <cstdint>
#include <functional>
#include <optional>
#include <utility>
#include <variant>
Expand All @@ -30,6 +31,8 @@ namespace litert::internal {

// Extra info about how the buffer is handled during load or serialization.
struct BufferContext {
using Ref = std::reference_wrapper<BufferContext>;

// Whether the buffer should be appended to the flatbuffer during
// serialization.
bool should_append = false;
Expand Down Expand Up @@ -71,11 +74,11 @@ class BufferManager {
}

// Get the context of the buffer at the given id.
Expected<BufferContext> GetContext(BufferId id) {
Expected<BufferContext::Ref> GetContext(BufferId id) {
if (id >= buffers_.size()) {
return Error(kLiteRtStatusErrorIndexOOB);
}
return buffers_[id].second;
return std::ref(buffers_[id].second);
}

// Number of buffers. Ids will be 0 <-> num - 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST(BufferManagerTest, RegisterWithContext) {

EXPECT_EQ(manager.NumBuffers(), 2);
EXPECT_EQ(manager.GetBuffer(id)->StrView(), kData);
EXPECT_EQ(manager.GetContext(id)->should_append, true);
EXPECT_EQ(manager.GetContext(id)->get().should_append, true);
}

} // namespace
Expand Down

0 comments on commit 799ada6

Please sign in to comment.