From 0fbb247a5e7cb1858d093b9e440b8200be3e0b55 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Tue, 27 Feb 2018 14:26:03 +0100 Subject: Remove small write_{config,autoconf}() optimizations They're really minor, and copying them around when new output functions are added gets a bit silly. These functions are used as a reference too, so maximum readability helps. --- kconfiglib.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index c54d131..9001719 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -838,10 +838,7 @@ class Kconfig(object): and include a final terminating newline. """ with open(filename, "w") as f: - # Small optimization - write = f.write - - write(header) + f.write(header) # Avoid duplicates -- see write_config() for sym in self.defined_syms: @@ -857,22 +854,22 @@ class Kconfig(object): if sym._write_to_conf: if sym.orig_type in (BOOL, TRISTATE): if val != "n": - write("#define {}{}{} 1\n" - .format(self.config_prefix, sym.name, - "_MODULE" if val == "m" else "")) + f.write("#define {}{}{} 1\n" + .format(self.config_prefix, sym.name, + "_MODULE" if val == "m" else "")) elif sym.orig_type == STRING: - write('#define {}{} "{}"\n' - .format(self.config_prefix, sym.name, - escape(val))) + f.write('#define {}{} "{}"\n' + .format(self.config_prefix, sym.name, + escape(val))) elif sym.orig_type in (INT, HEX): if sym.orig_type == HEX and \ not val.startswith(("0x", "0X")): val = "0x" + val - write("#define {}{} {}\n" - .format(self.config_prefix, sym.name, val)) + f.write("#define {}{} {}\n" + .format(self.config_prefix, sym.name, val)) else: _internal_error("Internal error while creating C " @@ -902,10 +899,7 @@ class Kconfig(object): and include a final terminating newline. """ with open(filename, "w") as f: - # Small optimization - write = f.write - - write(header) + f.write(header) # Symbol._written is set to True when a symbol config string is # fetched, so that symbols defined in multiple locations only get @@ -930,13 +924,13 @@ class Kconfig(object): if isinstance(item, Symbol): if not item._written: item._written = True - write(item.config_string) + f.write(item.config_string) elif expr_value(node.dep) and \ ((item == MENU and expr_value(node.visibility)) or item == COMMENT): - write("\n#\n# {}\n#\n".format(node.prompt[0])) + f.write("\n#\n# {}\n#\n".format(node.prompt[0])) # Iterative tree walk using parent pointers -- cgit v1.2.3