From 276afc7983629400154749e7231c77ba2a7c3788 Mon Sep 17 00:00:00 2001 From: StunxFS Date: Mon, 30 Oct 2023 21:26:22 -0400 Subject: [PATCH] refact(core): use an array instead of a vector for the return trace stack --- lib/core/src/errors.ri | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/core/src/errors.ri b/lib/core/src/errors.ri index d174c07d7..90c51fef0 100644 --- a/lib/core/src/errors.ri +++ b/lib/core/src/errors.ri @@ -20,16 +20,26 @@ struct CallTrace { line: usize; } +// NOTE: 50 should be fine for now. +const RETURN_TRACE_MAX_SIZE = 50; + struct ReturnTrace { - mut traces: []CallTrace = @vec(CallTrace, 5); + traces: [RETURN_TRACE_MAX_SIZE]mut CallTrace; + mut cur_idx: usize; #[inline] func add(mut self, trace: CallTrace) { - self.traces.push(trace); + if self.cur_idx == RETURN_TRACE_MAX_SIZE { + process_panic("maximum return trace size exceeded"); + } + self.traces[self.cur_idx] = trace; + self.cur_idx += 1; } func print(self) { - for trace in self.traces { + mut i: usize := 0; + while i < self.cur_idx : i += 1 { + trace := self.traces[i]; console_eprintln( " from {} in \"{}\":{}", demangle_symbol(trace.name), trace.file, trace.line @@ -38,7 +48,7 @@ struct ReturnTrace { } func clear(mut self) { - self.traces.clear(); + self.cur_idx = 0; } }