Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: kdoc: move the core dispatch into a state table

Since all of the handlers already nicely have the same prototype, put them
into a table and call them from there and take out the extended
if-then-else series.

Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250606163438.229916-3-corbet@lwn.net

+17 -13
+17 -13
scripts/lib/kdoc/kdoc_parser.py
··· 1678 1678 1679 1679 return export_table 1680 1680 1681 + # 1682 + # The state/action table telling us which function to invoke in 1683 + # each state. 1684 + # 1685 + state_actions = { 1686 + state.NORMAL: process_normal, 1687 + state.NAME: process_name, 1688 + state.BODY: process_body, 1689 + state.BODY_MAYBE: process_body, 1690 + state.BODY_WITH_BLANK_LINE: process_body, 1691 + state.INLINE: process_inline, 1692 + state.PROTO: process_proto, 1693 + state.DOCBLOCK: process_docblock, 1694 + } 1695 + 1681 1696 def parse_kdoc(self): 1682 1697 """ 1683 1698 Open and process each line of a C source file. ··· 1744 1729 self.process_export(export_table, line) 1745 1730 1746 1731 # Hand this line to the appropriate state handler 1747 - if self.state == state.NORMAL: 1748 - self.process_normal(ln, line) 1749 - elif self.state == state.NAME: 1750 - self.process_name(ln, line) 1751 - elif self.state in [state.BODY, state.BODY_MAYBE, 1752 - state.BODY_WITH_BLANK_LINE]: 1753 - self.process_body(ln, line) 1754 - elif self.state == state.INLINE: # scanning for inline parameters 1755 - self.process_inline(ln, line) 1756 - elif self.state == state.PROTO: 1757 - self.process_proto(ln, line) 1758 - elif self.state == state.DOCBLOCK: 1759 - self.process_docblock(ln, line) 1732 + self.state_actions[self.state](self, ln, line) 1733 + 1760 1734 except OSError: 1761 1735 self.config.log.error(f"Error: Cannot open file {self.fname}") 1762 1736