diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-12 18:16:49 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-12 18:21:15 +0100 |
| commit | 7b005123a364660f8ea8d801f84bf7a5f746d654 (patch) | |
| tree | 0b3da54e5ea7b44b64ca121849d8670f1ee92da1 /src/css/lunit.nim | |
| parent | c3065fad6dcf831b055a6b8d23d47fa3acb1326f (diff) | |
| download | chawan-7b005123a364660f8ea8d801f84bf7a5f746d654.tar.gz | |
cssvalues: reduce CSSValues size
* switch from float64 -> float32; other browsers use 32-bit floats too
* specify integer size as 32-bit
* use NetworkBitmap for background-image value (currently just an
invalid dummy value)
* remove "none" property & value types
CSSValue's payload is always one word (plus another for the type tag).
CSSValues keeps its size, but no longer has to heap-alloc + refcount
word-sized CSSValues.
(On 32-bit systems, CSSValues might actually be larger than before,
but I expect it's still a net benefit with the removal of refcounting
and the switch to 32-bit floats.)
Diffstat (limited to 'src/css/lunit.nim')
| -rw-r--r-- | src/css/lunit.nim | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/css/lunit.nim b/src/css/lunit.nim index ea41b9dc..a1acab48 100644 --- a/src/css/lunit.nim +++ b/src/css/lunit.nim @@ -57,6 +57,10 @@ func `div`*(a, b: LUnit): LUnit {.inline.} = let b = int64(b) return LUnit((a div b) shr 6) +converter toLUnit*(a: int32): LUnit = + let a = int64(a) shl 6 + return satlu(a) + converter toLUnit*(a: int): LUnit = let a = int64(a) shl 6 return satlu(a) @@ -84,7 +88,7 @@ func `-=`*(a: var LUnit; b: LUnit) {.inline.} = func `*=`*(a: var LUnit; b: LUnit) {.inline.} = a = a * b -func toLUnit*(a: float64): LUnit = +func toLUnit*(a: float32): LUnit = let a = a * 64 if unlikely(a == Inf): return LUnit(high(int32)) @@ -92,11 +96,11 @@ func toLUnit*(a: float64): LUnit = return LUnit(low(int32)) return LUnit(int32(a)) -func toFloat64*(a: LUnit): float64 = - return float64(int32(a)) / 64 +func toFloat32*(a: LUnit): float64 = + return float32(int32(a)) / 64 func `$`*(a: LUnit): string = - $toFloat64(a) + $toFloat32(a) func min*(a, b: LUnit): LUnit {.borrow.} func max*(a, b: LUnit): LUnit {.borrow.} |