Skip to content

Commit

Permalink
use buffer when it's divisible by 8
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Nov 7, 2024
1 parent dfea500 commit dacd907
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 197 deletions.
9 changes: 6 additions & 3 deletions src/generators/typescript/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import {
getParamVarExpr,
getTypeParametersExpression,
isBigInt,
useBuffer,
} from "./utils";

/*
Expand Down Expand Up @@ -731,16 +732,18 @@ export function storeBool(bool: Bool): (builder: Builder) => void {
fieldStoreSuffix: "Bit"
}
} else {
let isBuffer = useBuffer(fieldType);
let suffix = isBuffer ? "Buffer" : "Bits";
exprForParam = {
argLoadExpr: convertToAST(fieldType.bits, ctx.constructor),
argStoreExpr: convertToAST(
fieldType.bits,
ctx.constructor,
id(ctx.name)
),
paramType: "BitString",
fieldLoadSuffix: "Bits",
fieldStoreSuffix: "Bits",
paramType: isBuffer ? "Buffer" : "BitString",
fieldLoadSuffix: suffix,
fieldStoreSuffix: suffix,
};
}
} else if (fieldType.kind == "TLBCellType") {
Expand Down
8 changes: 8 additions & 0 deletions src/generators/typescript/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
TLBBinaryOp,
TLBBitsType,
TLBCode,
TLBConstructor,
TLBMathExpr,
Expand Down Expand Up @@ -234,3 +235,10 @@ export function isBigInt(fieldType: TLBNumberType) {
}
return true;
}

export function useBuffer(bitsType: TLBBitsType) {
if (bitsType.bits instanceof TLBNumberExpr && (bitsType.bits.n % 8) == 0) {
return true;
}
return false;
}
Loading

0 comments on commit dacd907

Please sign in to comment.