From 911ac5e141796fede97d5e9ff493a2de1a3536e5 Mon Sep 17 00:00:00 2001 From: albert-github Date: Wed, 20 Apr 2022 12:44:19 +0200 Subject: [PATCH] Handling enums in settings that double as boolean Small speedup of the code, only store and thus look through items that have a bool_representtaion. --- src/configgen.py | 36 ++++++++++++------------------------ src/layout.cpp | 3 ++- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/configgen.py b/src/configgen.py index 83f2a30217c..1e44204fe69 100755 --- a/src/configgen.py +++ b/src/configgen.py @@ -424,15 +424,12 @@ def escape(value): if nv.nodeName == "value": value = nv.getAttribute('name') bool_representation = nv.getAttribute('bool_representation') - if value: - if bool_representation: - if bool_representation.upper() == 'YES': - enabled = "true" - else: - enabled = "false" - print(" {\"%s\", \"%s\", %s, %s}," % (name,escape(value),"true",enabled)) + if value and bool_representation: + if bool_representation.upper() == 'YES': + enabled = "true" else: - print(" {\"%s\", \"%s\", %s, %s}," % (name,escape(value),"false","false")) + enabled = "false" + print(" {\"%s\", \"%s\", %s}," % (name,escape(value),enabled)) def parseGroupMapGetter(node): map = { 'bool':'bool', 'string':'const QCString &', 'int':'int', 'list':'const StringVector &' } @@ -787,8 +784,7 @@ def main(): if n.nodeName == "group": parseGroupMapEnums(n) print("") - print("bool enumHasBool(QCString set, QCString val);") - print("bool enumBoolRepresentation(QCString set, QCString val);") + print("bool enumBoolRepresentation(QCString set, QCString val, bool *representation);") print("") print("class ConfigValues") print("{") @@ -847,7 +843,6 @@ def main(): print("#include \"configvalues.h\"") print("#include \"configimpl.h\"") print("#include ") - print("#include ") print("") print("const ConfigValues::Info *ConfigValues::get(const QCString &tag) const"); print("{"); @@ -898,7 +893,6 @@ def main(): print("{") print(" QCString setting;") print(" QCString value;") - print(" bool hasBool;") print(" bool representation;") print("};") print("struct EnumBool enumBool[] = {") @@ -908,22 +902,16 @@ def main(): parseGroupMapEnumsBool(n) print("};") print("") - print("bool enumHasBool(QCString set, QCString val)") + print("bool enumBoolRepresentation(QCString set, QCString val, bool *representation)") print("{") print(" for (uint i = 0; i < sizeof(enumBool) / sizeof(*enumBool); i++)") print(" {") - print(" if (enumBool[i].setting == set && enumBool[i].value == val) return enumBool[i].hasBool;") - print(" }") - print(" return false;") - print("}") - print("") - print("bool enumBoolRepresentation(QCString set, QCString val)") - print("{") - print(" for (uint i = 0; i < sizeof(enumBool) / sizeof(*enumBool); i++)") - print(" {") - print(" if (enumBool[i].hasBool && enumBool[i].setting == set && enumBool[i].value == val) return enumBool[i].representation;") + print(" if (enumBool[i].setting == set && enumBool[i].value == val)") + print(" {") + print(" *representation = enumBool[i].representation;") + print(" return true;") + print(" }") print(" }") - print(" assert(false);") print(" return false;") print("}") print("") diff --git a/src/layout.cpp b/src/layout.cpp index 2f8f287419f..e54825bbaad 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -91,7 +91,8 @@ static bool elemIsVisible(const XMLHandlers::Attributes &attrib,bool defVal=TRUE else if (opt && opt->type==ConfigValues::Info::String) { visible = ConfigValues::instance().*(opt->value.s); - if (opt->enumType && enumHasBool(id,visible)) return enumBoolRepresentation(id,visible); + bool representation = false; + if (opt->enumType && enumBoolRepresentation(id,visible,&representation)) return representation; } else if (!opt) {