Skip to content

Commit

Permalink
give proper move semantics to Handle<>
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelflinger committed Apr 23, 2024
1 parent 6146d07 commit 99eac62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions filament/backend/include/backend/Handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ class HandleBase {
HandleBase(HandleBase const& rhs) noexcept = default;
HandleBase& operator=(HandleBase const& rhs) noexcept = default;

HandleBase(HandleBase&& rhs) noexcept
: object(rhs.object) {
rhs.object = nullid;
}

HandleBase& operator=(HandleBase&& rhs) noexcept {
if (this != &rhs) {
object = rhs.object;
rhs.object = nullid;
}
return *this;
}

private:
HandleId object;
};
Expand All @@ -89,8 +102,10 @@ struct Handle : public HandleBase {
Handle() noexcept = default;

Handle(Handle const& rhs) noexcept = default;
Handle(Handle&& rhs) noexcept = default;

Handle& operator=(Handle const& rhs) noexcept = default;
Handle& operator=(Handle&& rhs) noexcept = default;

explicit Handle(HandleId id) noexcept : HandleBase(id) { }

Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/VertexBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ FVertexBuffer::FVertexBuffer(FEngine& engine, const VertexBuffer::Builder& build
void FVertexBuffer::terminate(FEngine& engine) {
FEngine::DriverApi& driver = engine.getDriverApi();
if (!mBufferObjectsEnabled) {
for (BufferObjectHandle const bo : mBufferObjects) {
for (BufferObjectHandle bo : mBufferObjects) {
driver.destroyBufferObject(bo);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/utils/include/utils/StructureOfArrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class StructureOfArraysBase {
return (soa.elementAt<E>(i) = other);
}
UTILS_ALWAYS_INLINE Type const& operator = (Type&& other) noexcept {
return (soa.elementAt<E>(i) = other);
return (soa.elementAt<E>(i) = std::forward<Type>(other));
}
// comparisons
UTILS_ALWAYS_INLINE bool operator==(Type const& other) const {
Expand Down

0 comments on commit 99eac62

Please sign in to comment.