@latticexyz/schema-type 2.0.0-main-8d51a034 → 2.0.0-main-db19ea39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/schema-type",
3
- "version": "2.0.0-main-8d51a034",
3
+ "version": "2.0.0-main-db19ea39",
4
4
  "description": "SchemaType enum for various languages",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,8 @@
32
32
  "forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",
33
33
  "rimraf": "^3.0.2",
34
34
  "tsup": "^6.7.0",
35
- "vitest": "0.31.4"
35
+ "vitest": "0.31.4",
36
+ "@latticexyz/gas-report": "2.0.0-main-db19ea39"
36
37
  },
37
38
  "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f",
38
39
  "scripts": {
@@ -41,6 +42,7 @@
41
42
  "clean": "pnpm run clean:js",
42
43
  "clean:js": "rimraf dist/typescript",
43
44
  "dev": "tsup --watch",
45
+ "gas-report": "mud-gas-report --save gas-report.json",
44
46
  "test": "vitest typecheck --run && vitest --run && forge test"
45
47
  }
46
48
  }
@@ -214,24 +214,17 @@ enum SchemaType {
214
214
  function getStaticByteLength(SchemaType schemaType) pure returns (uint256) {
215
215
  uint256 index = uint8(schemaType);
216
216
 
217
- if (index < 32) {
218
- // uint8-256
219
- return index + 1;
220
- } else if (index < 64) {
221
- // int8-256, offset by 32
222
- return index + 1 - 32;
223
- } else if (index < 96) {
224
- // bytes1-32, offset by 64
225
- return index + 1 - 64;
226
- }
227
-
228
- // Other static types
229
- if (schemaType == SchemaType.BOOL) {
230
- return 1;
217
+ if (index < 97) {
218
+ // SchemaType enum elements are cyclically ordered for optimal static length lookup
219
+ // indexes: 00-31, 32-63, 64-95, 96, 97, ...
220
+ // lengths: 01-32, 01-32, 01-32, 01, 20, (the rest are 0s)
221
+ unchecked {
222
+ return (index & 31) + 1;
223
+ }
231
224
  } else if (schemaType == SchemaType.ADDRESS) {
232
225
  return 20;
226
+ } else {
227
+ // Return 0 for all dynamic types
228
+ return 0;
233
229
  }
234
-
235
- // Return 0 for all dynamic types
236
- return 0;
237
230
  }