Skip to content

Commit 911ac5e

Browse files
committed
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.
1 parent 2b61279 commit 911ac5e

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

src/configgen.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,12 @@ def escape(value):
424424
if nv.nodeName == "value":
425425
value = nv.getAttribute('name')
426426
bool_representation = nv.getAttribute('bool_representation')
427-
if value:
428-
if bool_representation:
429-
if bool_representation.upper() == 'YES':
430-
enabled = "true"
431-
else:
432-
enabled = "false"
433-
print(" {\"%s\", \"%s\", %s, %s}," % (name,escape(value),"true",enabled))
427+
if value and bool_representation:
428+
if bool_representation.upper() == 'YES':
429+
enabled = "true"
434430
else:
435-
print(" {\"%s\", \"%s\", %s, %s}," % (name,escape(value),"false","false"))
431+
enabled = "false"
432+
print(" {\"%s\", \"%s\", %s}," % (name,escape(value),enabled))
436433

437434
def parseGroupMapGetter(node):
438435
map = { 'bool':'bool', 'string':'const QCString &', 'int':'int', 'list':'const StringVector &' }
@@ -787,8 +784,7 @@ def main():
787784
if n.nodeName == "group":
788785
parseGroupMapEnums(n)
789786
print("")
790-
print("bool enumHasBool(QCString set, QCString val);")
791-
print("bool enumBoolRepresentation(QCString set, QCString val);")
787+
print("bool enumBoolRepresentation(QCString set, QCString val, bool *representation);")
792788
print("")
793789
print("class ConfigValues")
794790
print("{")
@@ -847,7 +843,6 @@ def main():
847843
print("#include \"configvalues.h\"")
848844
print("#include \"configimpl.h\"")
849845
print("#include <unordered_map>")
850-
print("#include <cassert>")
851846
print("")
852847
print("const ConfigValues::Info *ConfigValues::get(const QCString &tag) const");
853848
print("{");
@@ -898,7 +893,6 @@ def main():
898893
print("{")
899894
print(" QCString setting;")
900895
print(" QCString value;")
901-
print(" bool hasBool;")
902896
print(" bool representation;")
903897
print("};")
904898
print("struct EnumBool enumBool[] = {")
@@ -908,22 +902,16 @@ def main():
908902
parseGroupMapEnumsBool(n)
909903
print("};")
910904
print("")
911-
print("bool enumHasBool(QCString set, QCString val)")
905+
print("bool enumBoolRepresentation(QCString set, QCString val, bool *representation)")
912906
print("{")
913907
print(" for (uint i = 0; i < sizeof(enumBool) / sizeof(*enumBool); i++)")
914908
print(" {")
915-
print(" if (enumBool[i].setting == set && enumBool[i].value == val) return enumBool[i].hasBool;")
916-
print(" }")
917-
print(" return false;")
918-
print("}")
919-
print("")
920-
print("bool enumBoolRepresentation(QCString set, QCString val)")
921-
print("{")
922-
print(" for (uint i = 0; i < sizeof(enumBool) / sizeof(*enumBool); i++)")
923-
print(" {")
924-
print(" if (enumBool[i].hasBool && enumBool[i].setting == set && enumBool[i].value == val) return enumBool[i].representation;")
909+
print(" if (enumBool[i].setting == set && enumBool[i].value == val)")
910+
print(" {")
911+
print(" *representation = enumBool[i].representation;")
912+
print(" return true;")
913+
print(" }")
925914
print(" }")
926-
print(" assert(false);")
927915
print(" return false;")
928916
print("}")
929917
print("")

src/layout.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ static bool elemIsVisible(const XMLHandlers::Attributes &attrib,bool defVal=TRUE
9191
else if (opt && opt->type==ConfigValues::Info::String)
9292
{
9393
visible = ConfigValues::instance().*(opt->value.s);
94-
if (opt->enumType && enumHasBool(id,visible)) return enumBoolRepresentation(id,visible);
94+
bool representation = false;
95+
if (opt->enumType && enumBoolRepresentation(id,visible,&representation)) return representation;
9596
}
9697
else if (!opt)
9798
{

0 commit comments

Comments
 (0)