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

Use perfect hash (gperf) for parsing color names #1848

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Conversation

Caellian
Copy link
Collaborator

@Caellian Caellian commented Apr 20, 2024

Replaces X11 color name lookup with something that's easier to maintain.

Performance

Possibly faster than previous implementation - previous used binary search (O(log n)) on sorted color names, new uses a perfect hash (O(1)).

Extensibility

The main selling point of this PR is that it replaces code that was hard to extend with something where people can easily add their own colors.

While writing this PR, I realized that the previous could could've just been simplified to achieve same extensibility, but I guess perf. hash scales better and doesn't require colors to be sorted in advance (though that can be automated).

Testing

Tested by preexisting tests.

@github-actions github-actions bot added the sources PR modifies project sources label Apr 20, 2024
@github-actions github-actions bot added the gh-actions Issue or PR that suggest changing GitHub actions label Apr 20, 2024
Comment on lines -53 to -56
#ifdef BUILD_X11
unsigned long Colour::to_x11_color(Display *display, int screen,
bool transparency, bool premultiply) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to x11-color.cc where previous matching function was.

@Caellian Caellian force-pushed the dev/cleanup-globals branch 2 times, most recently from 9a2ec7a to c69dcaf Compare April 20, 2024 08:45
@brndnmtthws brndnmtthws added the feature New feature PR or issue label Apr 21, 2024
@Caellian Caellian force-pushed the dev/cleanup-globals branch 3 times, most recently from cba15e6 to 8e07629 Compare April 23, 2024 20:39
Base automatically changed from dev/cleanup-globals to main April 23, 2024 21:15
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Copy link

netlify bot commented Apr 23, 2024

Deploy Preview for conkyweb ready!

Name Link
🔨 Latest commit 1aee714
🔍 Latest deploy log https://app.netlify.com/sites/conkyweb/deploys/6628a1f3e8972f00089e85cb
😎 Deploy Preview https://deploy-preview-1848--conkyweb.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added build system Issues and PRs related to build system (CMake) and process display: x11 Issue related to X11 backend labels Apr 23, 2024
Made CMake copy the file renamed in case gperf isn't available. This
should prevent the compiler from finding stub before generated file.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
@github-actions github-actions bot added the documentation Issue or PR that suggests documentation improvements label Apr 24, 2024
@Caellian Caellian merged commit 93ffab5 into main Apr 24, 2024
63 checks passed
@Caellian Caellian deleted the dev/color-perf-hash branch April 24, 2024 06:24
@LinuxOnTheDesktop
Copy link

This commit sounds good (so, thank you!) but just what does it mean for the writer of conkies? How should we give colour names now? Is the new system backwards compatible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system Issues and PRs related to build system (CMake) and process display: x11 Issue related to X11 backend documentation Issue or PR that suggests documentation improvements feature New feature PR or issue gh-actions Issue or PR that suggest changing GitHub actions sources PR modifies project sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants