From b87ee62e6c68c61fcdaa47f4181ea56b4057d66c Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Wed, 21 Feb 2024 10:51:24 -0500 Subject: [PATCH] Use `std::deque` for assertions --- src/asm/output.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/asm/output.cpp b/src/asm/output.cpp index f9036ec8..35ac193f 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -42,7 +42,6 @@ struct Assertion { struct Patch *patch; struct Section *section; char *message; - struct Assertion *next; }; const char *objectName; @@ -52,7 +51,7 @@ std::deque sectionList; // List of symbols to put in the object file static std::vector objectSymbols; -static struct Assertion *assertions = NULL; +static std::deque assertions; static struct FileStackNode *fileStackNodes = NULL; @@ -68,19 +67,6 @@ static uint32_t countPatches(struct Section const *sect) return r; } -// Count the number of assertions used in this object -static uint32_t countAsserts(void) -{ - struct Assertion *assert = assertions; - uint32_t count = 0; - - while (assert) { - count++; - assert = assert->next; - } - return count; -} - // Write a long to a file (little-endian) static void putlong(uint32_t i, FILE *f) { @@ -413,8 +399,7 @@ bool out_CreateAssert(enum AssertionType type, struct Expression const *expr, return false; } - assertion->next = assertions; - assertions = assertion; + assertions.push_front(assertion); return true; } @@ -497,15 +482,11 @@ void out_WriteObject(void) freesection(sect); } - putlong(countAsserts(), f); - struct Assertion *assert = assertions; - - while (assert != NULL) { - struct Assertion *next = assert->next; + putlong(assertions.size(), f); + for (struct Assertion *assert : assertions) { writeassert(assert, f); freeassert(assert); - assert = next; } fclose(f);