From 31f188dc62208a175fbeab6104a0e4f0ca261f48 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:51:20 +0800 Subject: [PATCH] Refactor alignment checks in gc.nim Simplified alignment checks by removing conditional statements. --- lib/system/gc.nim | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 63b8b2cbd2..e6146ce26d 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -463,10 +463,7 @@ proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer = var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell), alignment)) #gcAssert typ.kind in {tyString, tySequence} or size >= typ.base.size, "size too small" # Check that the user data (after the Cell header) is properly aligned - if alignment > MemAlign: - gcAssert((cast[int](cellToUsr(res)) and (alignment-1)) == 0, "newObj: 2.1") - else: - gcAssert((cast[int](res) and (MemAlign-1)) == 0, "newObj: 2.2") + gcAssert((cast[int](cellToUsr(res)) and (alignment-1)) == 0, "newObj: 2.1") # now it is buffered in the ZCT res.typ = typ setFrameInfo(res) @@ -519,10 +516,7 @@ proc newObjRC1(typ: PNimType, size: int): pointer {.compilerRtl, noinline, raise var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell), alignment)) sysAssert(allocInv(gch.region), "newObjRC1 after rawAlloc") # Check that the user data (after the Cell header) is properly aligned - if alignment > MemAlign: - sysAssert((cast[int](cellToUsr(res)) and (alignment-1)) == 0, "newObj: 2.1") - else: - sysAssert((cast[int](res) and (MemAlign-1)) == 0, "newObj: 2.2") + sysAssert((cast[int](cellToUsr(res)) and (alignment-1)) == 0, "newObj: 2.1") # now it is buffered in the ZCT res.typ = typ setFrameInfo(res)