From d864b27e35a91d10148ac65704010849d091d8e9 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Sun, 30 Oct 2022 13:49:06 -0700 Subject: [PATCH] turn off slice bounds checking in release mode This change removes bounds checking for Slices, which represents most indexable storage in the emulator. Removing these checks makes the emulator less safe, without a doubt. However, it amounts a roughly 5% improvement in the games tested. Most of the checks today occur in fixed-length arrays where the index cannot be out of bounds, so I'm chosing to make this tradeoff. --- src/crab.cr | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/crab.cr b/src/crab.cr index ef44777..ed7396c 100644 --- a/src/crab.cr +++ b/src/crab.cr @@ -1,3 +1,19 @@ +{% if flag?(:release) %} + # Disables bounds checking in release mode. + + struct Slice(T) + @[AlwaysInline] + def []=(index : Int, value : T) : T + @pointer[index] = value + end + + @[AlwaysInline] + def [](index : Int) : T + @pointer[index] + end + end +{% end %} + require "colorize" require "option_parser"