From ba09a833089cad86f863e652defdb8dc5dfda60c Mon Sep 17 00:00:00 2001 From: Luke Nezda Date: Mon, 22 May 2023 08:49:58 -0500 Subject: [PATCH 1/4] [#36] allow changing almost everything in Config using System Properties * note: used underscores instead of periods used in the joni.debug* options --- src/org/joni/Config.java | 79 +++++++++++++++++---------------- src/org/joni/ConfigSupport.java | 5 +++ src/org/joni/Search.java | 4 +- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java index c2a3be77..aab25c91 100644 --- a/src/org/joni/Config.java +++ b/src/org/joni/Config.java @@ -22,54 +22,55 @@ import java.io.PrintStream; public interface Config extends org.jcodings.Config { - final int CHAR_TABLE_SIZE = 256; - final boolean USE_NO_INVALID_QUANTIFIER = true; - final int SCANENV_MEMNODES_SIZE = 8; - - final boolean USE_NAMED_GROUP = true; - final boolean USE_SUBEXP_CALL = true; - final boolean USE_PERL_SUBEXP_CALL = true; - final boolean USE_BACKREF_WITH_LEVEL = true; /* \k, \k */ - - final boolean USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT = true; /* /(?:()|())*\2/ */ - final boolean USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE = true; /* /\n$/ =~ "\n" */ - final boolean USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR = true; - - final boolean CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS = true; - - final boolean USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE = false; - final boolean USE_CAPTURE_HISTORY = false; - final boolean USE_VARIABLE_META_CHARS = true; - final boolean USE_WORD_BEGIN_END = true; /* "\<": word-begin, "\>": word-end */ - final boolean USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE = true; - final boolean USE_SUNDAY_QUICK_SEARCH = true; - final boolean USE_CEC = false; - final boolean USE_DYNAMIC_OPTION = false; - final boolean USE_BYTE_MAP = OptExactInfo.OPT_EXACT_MAXLEN <= CHAR_TABLE_SIZE; - final boolean USE_INT_MAP_BACKWARD = false; - - final int NREGION = 10; - final int MAX_BACKREF_NUM = 1000; - final int MAX_CAPTURE_GROUP_NUM = 32767; - final int MAX_REPEAT_NUM = 100000; - final int MAX_MULTI_BYTE_RANGES_NUM = 10000; + final int CHAR_TABLE_SIZE = ConfigSupport.getInt("joni.char_table_size", 256); + final boolean USE_NO_INVALID_QUANTIFIER = ConfigSupport.getBoolean("joni.use_no_invalid_quantifier", true); + final int SCANENV_MEMNODES_SIZE = ConfigSupport.getInt("joni.scanenv_memnodes_size", 8); + + final boolean USE_NAMED_GROUP = ConfigSupport.getBoolean("joni.use_named_group", true); + final boolean USE_SUBEXP_CALL = ConfigSupport.getBoolean("joni.use_subexp_call", true); + final boolean USE_PERL_SUBEXP_CALL = ConfigSupport.getBoolean("joni.use_perl_subexp_call", true); + final boolean USE_BACKREF_WITH_LEVEL = ConfigSupport.getBoolean("joni.use_backref_with_level", true); /* \k, \k */ + + final boolean USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT = ConfigSupport.getBoolean("joni.use_monomaniac_check_captures_in_endless_repeat", true); /* /(?:()|())*\2/ */ + final boolean USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE = ConfigSupport.getBoolean("joni.use_newline_at_end_of_string_has_empty_line", true); /* /\n$/ =~ "\n" */ + final boolean USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR = ConfigSupport.getBoolean("joni.use_warning_redundant_nested_repeat_operator", true); + + final boolean CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS = ConfigSupport.getBoolean("joni.case_fold_is_applied_inside_negative_cclass", true); + + final boolean USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE = ConfigSupport.getBoolean("joni.use_match_range_must_be_inside_of_specified_range", false); + final boolean USE_CAPTURE_HISTORY = ConfigSupport.getBoolean("joni.use_capture_history", false); + final boolean USE_VARIABLE_META_CHARS = ConfigSupport.getBoolean("joni.use_variable_meta_chars", true); + final boolean USE_WORD_BEGIN_END = ConfigSupport.getBoolean("joni.use_word_begin_end", true); /* "\<": word-begin, "\>": word-end */ + final boolean USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE = ConfigSupport.getBoolean("joni.use_find_longest_search_all_of_range", true); + final boolean USE_SUNDAY_QUICK_SEARCH = ConfigSupport.getBoolean("joni.use_sunday_quick_search", true); + final boolean USE_CEC = ConfigSupport.getBoolean("joni.use_cec", false); + final boolean USE_DYNAMIC_OPTION = ConfigSupport.getBoolean("joni.use_dynamic_option", false); + final boolean USE_BYTE_MAP = ConfigSupport.getBoolean("joni.use_byte_map", OptExactInfo.OPT_EXACT_MAXLEN <= CHAR_TABLE_SIZE); + final boolean USE_INT_MAP_BACKWARD = ConfigSupport.getBoolean("joni.use_int_map_backward", false); + + final int NREGION = ConfigSupport.getInt("joni.nregion", 10); + final int MAX_BACKREF_NUM = ConfigSupport.getInt("joni.max_backref_num", 1000); + final int MAX_CAPTURE_GROUP_NUM = ConfigSupport.getInt("joni.max_capture_group_num", 32767); + final int MAX_REPEAT_NUM = ConfigSupport.getInt("joni.max_multi_byte_ranges_num", 100000); + final int MAX_MULTI_BYTE_RANGES_NUM = ConfigSupport.getInt("joni.max_multi_byte_ranges_num", 10000); // internal config - final boolean USE_OP_PUSH_OR_JUMP_EXACT = true; - final boolean USE_QTFR_PEEK_NEXT = true; + final boolean USE_OP_PUSH_OR_JUMP_EXACT = ConfigSupport.getBoolean("joni.use_op_push_or_jump_exact", true); + final boolean USE_QTFR_PEEK_NEXT = ConfigSupport.getBoolean("joni.use_qtfr_peek_next", true); - final int INIT_MATCH_STACK_SIZE = 64; + final int INIT_MATCH_STACK_SIZE = ConfigSupport.getInt("joni.init_match_stack_size", 64); - final boolean DONT_OPTIMIZE = false; + final boolean DONT_OPTIMIZE = ConfigSupport.getBoolean("joni.dont_optimize", false); - final boolean USE_STRING_TEMPLATES = true; // use embedded string templates in Regex object as byte arrays instead of compiling them into int bytecode array + // use embedded string templates in Regex object as byte arrays instead of compiling them into int bytecode array + final boolean USE_STRING_TEMPLATES = ConfigSupport.getBoolean("joni.use_string_templates", true); - final int MAX_CAPTURE_HISTORY_GROUP = 31; + final int MAX_CAPTURE_HISTORY_GROUP = ConfigSupport.getInt("joni.max_capture_history_group", 31); - final int CHECK_STRING_THRESHOLD_LEN = 7; - final int CHECK_BUFF_MAX_SIZE = 0x4000; + final int CHECK_STRING_THRESHOLD_LEN = ConfigSupport.getInt("joni.check_string_threshold_len", 7); + final int CHECK_BUFF_MAX_SIZE = ConfigSupport.getInt("joni.check_buff_max_size", 0x4000); final PrintStream log = System.out; final PrintStream err = System.err; diff --git a/src/org/joni/ConfigSupport.java b/src/org/joni/ConfigSupport.java index 2cd089b7..e12c1a59 100644 --- a/src/org/joni/ConfigSupport.java +++ b/src/org/joni/ConfigSupport.java @@ -5,4 +5,9 @@ static boolean getBoolean(String property, boolean def) { String value = System.getProperty(property, def ? "true" : "false"); return !value.equals("false"); } + + static int getInt(String property, int def) { + String value = System.getProperty(property); + return value != null ? Integer.parseInt(value) : def; + } } diff --git a/src/org/joni/Search.java b/src/org/joni/Search.java index 3f8ca1f6..5c729fd0 100644 --- a/src/org/joni/Search.java +++ b/src/org/joni/Search.java @@ -421,10 +421,10 @@ final int search(Matcher matcher, byte[]text, int textP, int textEnd, int textRa int targetP = regex.exactP; int targetEnd = regex.exactEnd; - int end, s, tlen1; + int end, s; int tail = targetEnd - 1; + int tlen1 = tail - targetP; if (USE_SUNDAY_QUICK_SEARCH) { - tlen1 = tail - targetP; end = textRange + tlen1; s = textP + tlen1; } else { From eede23d6fc450ba2c5e5be25f59950d270ce68ee Mon Sep 17 00:00:00 2001 From: Luke Nezda Date: Mon, 22 May 2023 11:55:54 -0500 Subject: [PATCH 2/4] fix indent --- src/org/joni/ConfigSupport.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/org/joni/ConfigSupport.java b/src/org/joni/ConfigSupport.java index e12c1a59..99e26335 100644 --- a/src/org/joni/ConfigSupport.java +++ b/src/org/joni/ConfigSupport.java @@ -6,8 +6,8 @@ static boolean getBoolean(String property, boolean def) { return !value.equals("false"); } - static int getInt(String property, int def) { - String value = System.getProperty(property); - return value != null ? Integer.parseInt(value) : def; - } + static int getInt(String property, int def) { + String value = System.getProperty(property); + return value != null ? Integer.parseInt(value) : def; + } } From 3603d6989cd5b1786d6fdcb9d5dc5dd899aa7894 Mon Sep 17 00:00:00 2001 From: Luke Nezda Date: Mon, 22 May 2023 12:00:35 -0500 Subject: [PATCH 3/4] add un-negated OPTIMIZE to initialize with per code review --- src/org/joni/Config.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java index aab25c91..e7da69d1 100644 --- a/src/org/joni/Config.java +++ b/src/org/joni/Config.java @@ -60,7 +60,8 @@ public interface Config extends org.jcodings.Config { final int INIT_MATCH_STACK_SIZE = ConfigSupport.getInt("joni.init_match_stack_size", 64); - final boolean DONT_OPTIMIZE = ConfigSupport.getBoolean("joni.dont_optimize", false); + final boolean OPTIMIZE = ConfigSupport.getBoolean("joni.optimize", true); + final boolean DONT_OPTIMIZE = !OPTIMIZE; // use embedded string templates in Regex object as byte arrays instead of compiling them into int bytecode array final boolean USE_STRING_TEMPLATES = ConfigSupport.getBoolean("joni.use_string_templates", true); From dd5b7ec2a14fc2a1a906d5a9a7d728529eb0e460 Mon Sep 17 00:00:00 2001 From: Luke Nezda Date: Mon, 22 May 2023 13:03:25 -0500 Subject: [PATCH 4/4] deprecated double-negated DONT_OPTIMIZE per code review --- src/org/joni/Config.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/joni/Config.java b/src/org/joni/Config.java index e7da69d1..ac9a71b3 100644 --- a/src/org/joni/Config.java +++ b/src/org/joni/Config.java @@ -61,6 +61,7 @@ public interface Config extends org.jcodings.Config { final int INIT_MATCH_STACK_SIZE = ConfigSupport.getInt("joni.init_match_stack_size", 64); final boolean OPTIMIZE = ConfigSupport.getBoolean("joni.optimize", true); + @Deprecated final boolean DONT_OPTIMIZE = !OPTIMIZE; // use embedded string templates in Regex object as byte arrays instead of compiling them into int bytecode array