Skip to content

compare C-string fields as C strings in find/count_items_with_string - #7903

Open
Goober5000 wants to merge 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/string_utilities
Open

Goober5000 wants to merge 1 commit into
scp-fs2open:masterfrom
Goober5000:fix/string_utilities

Conversation

@Goober5000

Copy link
Copy Markdown
Contributor

A char array field could not match the FIELD_T* member-pointer overloads, so it fell through to the SCP_string overload, which built a temporary SCP_string for the search string and for every item compared. Dispatch on the field's value instead: item_string_equal overloads compare C-string and char array fields with stricmp and SCP_string fields with lcase_equal, without allocating. This merges the twelve templates into four.

Add unit tests covering char*, char[N], and SCP_string fields.

@Goober5000 Goober5000 added cleanup A modification or rewrite of code to make it more understandable or easier to maintain. fix A fix for bugs, not-a-bugs, and/or regressions. labels Oct 18, 2026
A char array field could not match the FIELD_T* member-pointer overloads, so
it fell through to the SCP_string overload, which built a temporary SCP_string
for the search string and for every item compared.  Dispatch on the field's
value instead: item_string_equal overloads compare C-string and char array
fields with stricmp and SCP_string fields with lcase_equal, without
allocating.  This merges the twelve templates into four.

Add unit tests covering char*, char[N], and SCP_string fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup A modification or rewrite of code to make it more understandable or easier to maintain. fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant