Skip to content

Commit

Permalink
refactor(world-modules): simplify getUniqueEntity call (#2161)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Jan 19, 2024
1 parent 3a089d1 commit eaa766e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-garlics-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world-modules": patch
---

Removed `IUniqueEntitySystem` in favor of calling `getUniqueEntity` via `world.call` instead of the world function selector. This had a small gas improvement.
4 changes: 2 additions & 2 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "get a unique entity nonce (non-root module)",
"gasUsed": 51027
"gasUsed": 50365
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -321,6 +321,6 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "get a unique entity nonce (root module)",
"gasUsed": 51027
"gasUsed": 50368
}
]
7 changes: 0 additions & 7 deletions packages/world-modules/src/interfaces/IUniqueEntitySystem.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity >=0.8.21;

import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";

import { IUniqueEntitySystem } from "../../interfaces/IUniqueEntitySystem.sol";
import { UniqueEntitySystem } from "./UniqueEntitySystem.sol";

import { SystemSwitch } from "../../utils/SystemSwitch.sol";
Expand All @@ -23,5 +22,5 @@ function getUniqueEntity() returns (bytes32 uniqueEntity) {
* Increment and get an entity nonce.
*/
function getUniqueEntity(IBaseWorld world) returns (bytes32 uniqueEntity) {
return IUniqueEntitySystem(address(world)).uniqueEntity_system_getUniqueEntity();
return abi.decode(world.call(SYSTEM_ID, abi.encodeCall(UniqueEntitySystem.getUniqueEntity, ())), (bytes32));
}

0 comments on commit eaa766e

Please sign in to comment.