Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: make SQString::Create that supports std::string and use that #11015

Merged
merged 1 commit into from Jun 20, 2023

Conversation

rubidium42
Copy link
Contributor

Motivation / Problem

Number of places doing .c_str() to then (implicitly) run strlen to determine the length within the Squirrel API.

Description

Add std::string supporting function to create SQString that passes the string size to the function that actually creates the object.

Limitations

None.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@LordAro
Copy link
Member

LordAro commented Jun 15, 2023

changing from c_str to data without any changes to length/size makes me uncomfortable

@rubidium42
Copy link
Contributor Author

changing from c_str to data without any changes to length/size makes me uncomfortable

1: since C++11 .data() and .c_str() are defined/specified to be the same. The specifications literally says: "The returned array is null-terminated, that is, data() and c_str() perform the same function.".
2: we are already passing the string's size there, unless the size is overridden by the caller. So conceptually .data() and .size() seem better than .c_str() and .size().

@rubidium42 rubidium42 merged commit 4fbc810 into OpenTTD:master Jun 20, 2023
19 checks passed
@rubidium42 rubidium42 deleted the squirrel-c_str branch June 20, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants