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: Use std::string in console commands/aliases registration, and std::map instead our sorted linked list #9057

Merged
merged 4 commits into from Apr 24, 2021

Conversation

glx22
Copy link
Contributor

@glx22 glx22 commented Apr 18, 2021

Multiple commits to ease reviewing, but should be squashed I think.

Motivation / Problem

When registering a command or alias in console, memory is manually allocated to store the data in global custom sorted linked lists. And we rely on OS to free this memory at exit.

Also, underscores are removed from commands/aliases names on registration, but each access needs to remove underscores to find them (and some were forgetting the removal, at least info_cmd). And names in list_cmds output didn't match names shown in help.

Description

std::string is used to store names, and alias command.
Custom sorted linked list is replaced with std::map enclosed inside a static struct.
Map key uses names without underscores, but commands/aliases themselves store the name with underscores for display.
Underscore removal is handled inside the accessors, so the caller doesn't have to care about it.

Limitations

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 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')

src/console_internal.h Outdated Show resolved Hide resolved
src/console.cpp Outdated Show resolved Hide resolved
src/console_cmds.cpp Outdated Show resolved Hide resolved
src/console_internal.h Outdated Show resolved Hide resolved
src/console.cpp Show resolved Hide resolved
src/console.cpp Show resolved Hide resolved
src/console.cpp Outdated Show resolved Hide resolved
src/console.cpp Outdated Show resolved Hide resolved
@glx22 glx22 merged commit 888389c into OpenTTD:master Apr 24, 2021
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

3 participants