aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/indent
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-12-02 16:28:18 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-12-02 16:28:18 +0000
commitb30bb755da3d57e5f41d6ab9338f2ce4b17640de (patch)
tree3bf8ceb569878d23fef0046b50b0b1c60b2cfd26 /usr.bin/indent
parent669f39b29c127c6a97e2341c4c7396bec34c604d (diff)
downloadsrc-b30bb755da3d57e5f41d6ab9338f2ce4b17640de.tar.gz
src-b30bb755da3d57e5f41d6ab9338f2ce4b17640de.zip
indent(1): Optimize parser stack usage.
When special else-if processing is enabled (-ei), we can assume "else if" and "if" to be equivalent for indentation purposes. This reduction saves a lot of stack space in case of a long "if-else-if ... else-if" sequence; with this change, Postgres/src/bin/psql/tab-complete.c as of 9.6beta3 requires minimum of the stack length to be 31 instead of 444. Submitted by: Piotr Sephaniak
Notes
Notes: svn path=/head/; revision=309415
Diffstat (limited to 'usr.bin/indent')
-rw-r--r--usr.bin/indent/parse.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c
index 52f21270096e..b2afe54413bd 100644
--- a/usr.bin/indent/parse.c
+++ b/usr.bin/indent/parse.c
@@ -94,7 +94,13 @@ parse(int tk) /* tk: the code for the construct scanned */
case ifstmt: /* scanned if (...) */
if (ps.p_stack[ps.tos] == elsehead && ps.else_if) /* "else if ..." */
- ps.i_l_follow = ps.il[ps.tos];
+ /*
+ * Note that the stack pointer here is decremented, effectively
+ * reducing "else if" to "if". This saves a lot of stack space
+ * in case of a long "if-else-if ... else-if" sequence.
+ */
+ ps.i_l_follow = ps.il[ps.tos--];
+
/* the rest is the same as for dolit and forstmt */
case dolit: /* 'do' */
case forstmt: /* for (...) */