From da05d1e1c21fa517f82063968827c8fc70ff1183 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 5 Jan 2021 23:27:49 +0100 Subject: [PATCH] Add Pop to the list of idents that GetNextShortest can't generate It's unlikely to hit this one (requires more than 10,000 identifiers to trigger) but it's a bug nevertheless. While touching the file, try to explain the situation better in the first comment. --- lslopt/lslrenamer.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lslopt/lslrenamer.py b/lslopt/lslrenamer.py index 99555a6..6a76a2e 100644 --- a/lslopt/lslrenamer.py +++ b/lslopt/lslrenamer.py @@ -15,11 +15,12 @@ # You should have received a copy of the GNU General Public License # along with LSL PyOptimizer. If not, see . -# This module renames all kinds of variables. Globals and function/event -# parameters take memory space, so shrinking the identifiers as much as -# possible ensures their memory usage will be minimized. It also reuses some -# preexisting names when possible. Locals are renamed also so that they don't -# stand in the way of globals. +# This module renames all kinds of variables. Global variables, user functions, +# state names, event names and function/event parameters all take memory space, +# so shrinking the identifiers as much as possible, when possible (i.e. not for +# events or the default state), ensures their memory usage will be minimized. +# It also reuses some preexisting names. Locals are renamed also so that they +# don't stand in the way of globals. # # A side effect of this change is that the script becomes unreadable gibberish. @@ -28,8 +29,11 @@ from strutil import xrange class renamer(object): CharSet1 = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' CharSet2 = '0123456789_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' + # As a special case, 'Pop' is not a keyword, but it's one of the predefined + # identifiers, therefore it must not be generated by GetNextShortest + # because it's already in the list of identifiers available from the start. Kws = frozenset({'do', 'if', 'PI', - 'for', 'key', 'EOF', + 'for', 'key', 'EOF', 'Pop', 'jump', 'else', 'list', 'TRUE', 'LOOP', 'case' }) def GetNextShortest(self):