Cleanup text_object
construction in core.cc
#2052
Labels
enhancement
Issue that suggests an enhancement
priority: low
A low priority issue or PR
text
Issue or PR related to `conky.text` variables
Currently, in
core.cc
,construct_text_object
function uses a ~1600 lines long if-elseif chain.All of those are wrapped in macros and really difficult to reason about.
I propose all those macros get replaced with functions that handle parameters and construction in a cleaner C++ way, and gperf can be used to generate a hash based lookup for the appropriate function pointer.
A single function dereference ought to be faster than 450+ consecutive
strcmp
s. But performance isn't really as much the point as this code being very unreadable:The macro processor effectively produces a chain of blocks looking like this:
and the entire chain can be simplified to:
CMake can collect these
populate_object_function
functions, generate a gperf input file and produce a perfect hash as part of the build process. Using gperf (again) isn't really the point, it would be ok to generate the same if-elseif chain from the build command, but I'd like to avoid having all those constructors as part of a huge macro sequence because its unsightly, hard to understand, and makes clang-format and syntax highlighting go "wuut".This is a very tedious change that's mostly aimed at making this file easier to understand and maintain, but that's why I'm marking this issue as a low priority enhancement.
The text was updated successfully, but these errors were encountered: