Skip to content

Commit 2044540

Browse files
authored
Merge pull request #79 from sebthom/refact
refact: code cleanup
2 parents 03ac9a5 + d5b8f78 commit 2044540

32 files changed

Lines changed: 492 additions & 495 deletions

src/org/joni/Analyser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ private Node expandCaseFoldString(Node node) {
16071607
int altNum = 1;
16081608

16091609
ListNode topRoot = null, root = null;
1610-
ObjPtr<Node> prevNode = new ObjPtr<Node>();
1610+
ObjPtr<Node> prevNode = new ObjPtr<>();
16111611
StringNode stringNode = null;
16121612

16131613
while (p < end) {

src/org/joni/Config.java

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,68 @@
2222
import java.io.PrintStream;
2323

2424
public interface Config extends org.jcodings.Config {
25-
final int REGEX_MAX_LENGTH = ConfigSupport.getInt("joni.regex_max_length", -1);
26-
final int CHAR_TABLE_SIZE = ConfigSupport.getInt("joni.char_table_size", 256);
27-
final boolean USE_NO_INVALID_QUANTIFIER = ConfigSupport.getBoolean("joni.use_no_invalid_quantifier", true);
28-
final int SCANENV_MEMNODES_SIZE = ConfigSupport.getInt("joni.scanenv_memnodes_size", 8);
29-
30-
final boolean USE_NAMED_GROUP = ConfigSupport.getBoolean("joni.use_named_group", true);
31-
final boolean USE_SUBEXP_CALL = ConfigSupport.getBoolean("joni.use_subexp_call", true);
32-
final boolean USE_PERL_SUBEXP_CALL = ConfigSupport.getBoolean("joni.use_perl_subexp_call", true);
33-
final boolean USE_BACKREF_WITH_LEVEL = ConfigSupport.getBoolean("joni.use_backref_with_level", true); /* \k<name+n>, \k<name-n> */
34-
35-
final boolean USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT = ConfigSupport.getBoolean("joni.use_monomaniac_check_captures_in_endless_repeat", true); /* /(?:()|())*\2/ */
36-
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" */
37-
final boolean USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR = ConfigSupport.getBoolean("joni.use_warning_redundant_nested_repeat_operator", true);
38-
39-
final boolean CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS = ConfigSupport.getBoolean("joni.case_fold_is_applied_inside_negative_cclass", true);
40-
41-
final boolean USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE = ConfigSupport.getBoolean("joni.use_match_range_must_be_inside_of_specified_range", false);
42-
final boolean USE_CAPTURE_HISTORY = ConfigSupport.getBoolean("joni.use_capture_history", false);
43-
final boolean USE_VARIABLE_META_CHARS = ConfigSupport.getBoolean("joni.use_variable_meta_chars", true);
44-
final boolean USE_WORD_BEGIN_END = ConfigSupport.getBoolean("joni.use_word_begin_end", true); /* "\<": word-begin, "\>": word-end */
45-
final boolean USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE = ConfigSupport.getBoolean("joni.use_find_longest_search_all_of_range", true);
46-
final boolean USE_SUNDAY_QUICK_SEARCH = ConfigSupport.getBoolean("joni.use_sunday_quick_search", true);
47-
final boolean USE_CEC = ConfigSupport.getBoolean("joni.use_cec", false);
48-
final boolean USE_DYNAMIC_OPTION = ConfigSupport.getBoolean("joni.use_dynamic_option", false);
49-
final boolean USE_BYTE_MAP = ConfigSupport.getBoolean("joni.use_byte_map", OptExactInfo.OPT_EXACT_MAXLEN <= CHAR_TABLE_SIZE);
50-
final boolean USE_INT_MAP_BACKWARD = ConfigSupport.getBoolean("joni.use_int_map_backward", false);
51-
52-
final int NREGION = ConfigSupport.getInt("joni.nregion", 10);
53-
final int MAX_BACKREF_NUM = ConfigSupport.getInt("joni.max_backref_num", 1000);
54-
final int MAX_CAPTURE_GROUP_NUM = ConfigSupport.getInt("joni.max_capture_group_num", 32767);
55-
final int MAX_REPEAT_NUM = ConfigSupport.getInt("joni.max_multi_byte_ranges_num", 100000);
56-
final int MAX_MULTI_BYTE_RANGES_NUM = ConfigSupport.getInt("joni.max_multi_byte_ranges_num", 10000);
25+
int REGEX_MAX_LENGTH = ConfigSupport.getInt("joni.regex_max_length", -1);
26+
int CHAR_TABLE_SIZE = ConfigSupport.getInt("joni.char_table_size", 256);
27+
boolean USE_NO_INVALID_QUANTIFIER = ConfigSupport.getBoolean("joni.use_no_invalid_quantifier", true);
28+
int SCANENV_MEMNODES_SIZE = ConfigSupport.getInt("joni.scanenv_memnodes_size", 8);
29+
30+
boolean USE_NAMED_GROUP = ConfigSupport.getBoolean("joni.use_named_group", true);
31+
boolean USE_SUBEXP_CALL = ConfigSupport.getBoolean("joni.use_subexp_call", true);
32+
boolean USE_PERL_SUBEXP_CALL = ConfigSupport.getBoolean("joni.use_perl_subexp_call", true);
33+
boolean USE_BACKREF_WITH_LEVEL = ConfigSupport.getBoolean("joni.use_backref_with_level", true); /* \k<name+n>, \k<name-n> */
34+
35+
boolean USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT = ConfigSupport.getBoolean("joni.use_monomaniac_check_captures_in_endless_repeat", true); /* /(?:()|())*\2/ */
36+
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" */
37+
boolean USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR = ConfigSupport.getBoolean("joni.use_warning_redundant_nested_repeat_operator", true);
38+
39+
boolean CASE_FOLD_IS_APPLIED_INSIDE_NEGATIVE_CCLASS = ConfigSupport.getBoolean("joni.case_fold_is_applied_inside_negative_cclass", true);
40+
41+
boolean USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE = ConfigSupport.getBoolean("joni.use_match_range_must_be_inside_of_specified_range", false);
42+
boolean USE_CAPTURE_HISTORY = ConfigSupport.getBoolean("joni.use_capture_history", false);
43+
boolean USE_VARIABLE_META_CHARS = ConfigSupport.getBoolean("joni.use_variable_meta_chars", true);
44+
boolean USE_WORD_BEGIN_END = ConfigSupport.getBoolean("joni.use_word_begin_end", true); /* "\<": word-begin, "\>": word-end */
45+
boolean USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE = ConfigSupport.getBoolean("joni.use_find_longest_search_all_of_range", true);
46+
boolean USE_SUNDAY_QUICK_SEARCH = ConfigSupport.getBoolean("joni.use_sunday_quick_search", true);
47+
boolean USE_CEC = ConfigSupport.getBoolean("joni.use_cec", false);
48+
boolean USE_DYNAMIC_OPTION = ConfigSupport.getBoolean("joni.use_dynamic_option", false);
49+
boolean USE_BYTE_MAP = ConfigSupport.getBoolean("joni.use_byte_map", OptExactInfo.OPT_EXACT_MAXLEN <= CHAR_TABLE_SIZE);
50+
boolean USE_INT_MAP_BACKWARD = ConfigSupport.getBoolean("joni.use_int_map_backward", false);
51+
52+
int NREGION = ConfigSupport.getInt("joni.nregion", 10);
53+
int MAX_BACKREF_NUM = ConfigSupport.getInt("joni.max_backref_num", 1000);
54+
int MAX_CAPTURE_GROUP_NUM = ConfigSupport.getInt("joni.max_capture_group_num", 32767);
55+
int MAX_REPEAT_NUM = ConfigSupport.getInt("joni.max_multi_byte_ranges_num", 100000);
56+
int MAX_MULTI_BYTE_RANGES_NUM = ConfigSupport.getInt("joni.max_multi_byte_ranges_num", 10000);
5757

5858
// internal config
59-
final boolean USE_OP_PUSH_OR_JUMP_EXACT = ConfigSupport.getBoolean("joni.use_op_push_or_jump_exact", true);
60-
final boolean USE_QTFR_PEEK_NEXT = ConfigSupport.getBoolean("joni.use_qtfr_peek_next", true);
59+
boolean USE_OP_PUSH_OR_JUMP_EXACT = ConfigSupport.getBoolean("joni.use_op_push_or_jump_exact", true);
60+
boolean USE_QTFR_PEEK_NEXT = ConfigSupport.getBoolean("joni.use_qtfr_peek_next", true);
6161

62-
final int INIT_MATCH_STACK_SIZE = ConfigSupport.getInt("joni.init_match_stack_size", 64);
62+
int INIT_MATCH_STACK_SIZE = ConfigSupport.getInt("joni.init_match_stack_size", 64);
6363

64-
final boolean OPTIMIZE = ConfigSupport.getBoolean("joni.optimize", true);
65-
@Deprecated
66-
final boolean DONT_OPTIMIZE = !OPTIMIZE;
64+
boolean OPTIMIZE = ConfigSupport.getBoolean("joni.optimize", true);
65+
@Deprecated boolean DONT_OPTIMIZE = !OPTIMIZE;
6766

6867
// use embedded string templates in Regex object as byte arrays instead of compiling them into int bytecode array
69-
final boolean USE_STRING_TEMPLATES = ConfigSupport.getBoolean("joni.use_string_templates", true);
68+
boolean USE_STRING_TEMPLATES = ConfigSupport.getBoolean("joni.use_string_templates", true);
7069

7170

72-
final int MAX_CAPTURE_HISTORY_GROUP = ConfigSupport.getInt("joni.max_capture_history_group", 31);
71+
int MAX_CAPTURE_HISTORY_GROUP = ConfigSupport.getInt("joni.max_capture_history_group", 31);
7372

7473

75-
final int CHECK_STRING_THRESHOLD_LEN = ConfigSupport.getInt("joni.check_string_threshold_len", 7);
76-
final int CHECK_BUFF_MAX_SIZE = ConfigSupport.getInt("joni.check_buff_max_size", 0x4000);
74+
int CHECK_STRING_THRESHOLD_LEN = ConfigSupport.getInt("joni.check_string_threshold_len", 7);
75+
int CHECK_BUFF_MAX_SIZE = ConfigSupport.getInt("joni.check_buff_max_size", 0x4000);
7776

78-
final PrintStream log = System.out;
79-
final PrintStream err = System.err;
77+
PrintStream log = System.out;
78+
PrintStream err = System.err;
8079

81-
final boolean DEBUG_ALL = ConfigSupport.getBoolean("joni.debug.all", false);
80+
boolean DEBUG_ALL = ConfigSupport.getBoolean("joni.debug.all", false);
8281

83-
final boolean DEBUG = ConfigSupport.getBoolean("joni.debug", false) || DEBUG_ALL;
84-
final boolean DEBUG_PARSE_TREE = ConfigSupport.getBoolean("joni.debug.parse.tree", false) || DEBUG_ALL;
85-
final boolean DEBUG_PARSE_TREE_RAW = ConfigSupport.getBoolean("joni.debug.parse.tree.raw", true) || DEBUG_ALL;
86-
final boolean DEBUG_COMPILE = ConfigSupport.getBoolean("joni.debug.compile", false) || DEBUG_ALL;
87-
final boolean DEBUG_COMPILE_BYTE_CODE_INFO = ConfigSupport.getBoolean("joni.debug.compile.bytecode.info", false) || DEBUG_ALL;
88-
final boolean DEBUG_SEARCH = ConfigSupport.getBoolean("joni.debug.search", false) || DEBUG_ALL;
89-
final boolean DEBUG_MATCH = ConfigSupport.getBoolean("joni.debug.match", false) || DEBUG_ALL;
82+
boolean DEBUG = ConfigSupport.getBoolean("joni.debug", false) || DEBUG_ALL;
83+
boolean DEBUG_PARSE_TREE = ConfigSupport.getBoolean("joni.debug.parse.tree", false) || DEBUG_ALL;
84+
boolean DEBUG_PARSE_TREE_RAW = ConfigSupport.getBoolean("joni.debug.parse.tree.raw", true) || DEBUG_ALL;
85+
boolean DEBUG_COMPILE = ConfigSupport.getBoolean("joni.debug.compile", false) || DEBUG_ALL;
86+
boolean DEBUG_COMPILE_BYTE_CODE_INFO = ConfigSupport.getBoolean("joni.debug.compile.bytecode.info", false) || DEBUG_ALL;
87+
boolean DEBUG_SEARCH = ConfigSupport.getBoolean("joni.debug.search", false) || DEBUG_ALL;
88+
boolean DEBUG_MATCH = ConfigSupport.getBoolean("joni.debug.match", false) || DEBUG_ALL;
9089
}

src/org/joni/Lexer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private boolean strExistCheckWithEsc(int[]s, int n, int bad) {
522522
return false;
523523
}
524524

525-
private static final int send[] = new int[]{':', ']'};
525+
private static final int[] send = new int[]{':', ']'};
526526

527527
private void fetchTokenInCCFor_charType(boolean flag, int type) {
528528
token.type = TokenType.CHAR_TYPE;

src/org/joni/MinMaxLen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class MinMaxLen {
2424
int max; /* max byte length */
2525

2626
/* 1000 / (min-max-dist + 1) */
27-
private static final short distValues[] = {
27+
private static final short[] distValues = {
2828
1000, 500, 333, 250, 200, 167, 143, 125, 111, 100,
2929
91, 83, 77, 71, 67, 63, 59, 56, 53, 50,
3030
48, 45, 43, 42, 40, 38, 37, 36, 34, 33,

src/org/joni/NameEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class NameEntry {
2828

2929
int backNum;
3030
int backRef1;
31-
int backRefs[];
31+
int[] backRefs;
3232

3333
public NameEntry(byte[]bytes, int p, int end) {
3434
name = bytes;

src/org/joni/OptExactInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class OptExactInfo {
2828
final OptAnchorInfo anchor = new OptAnchorInfo();
2929
boolean reachEnd;
3030
int ignoreCase; /* -1: unset, 0: case sensitive, 1: ignore case */
31-
final byte bytes[] = new byte[OPT_EXACT_MAXLEN];
31+
final byte[] bytes = new byte[OPT_EXACT_MAXLEN];
3232
int length;
3333

3434
boolean isFull() {

src/org/joni/OptMapInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class OptMapInfo {
2626
final MinMaxLen mmd = new MinMaxLen(); /* info position */
2727
final OptAnchorInfo anchor = new OptAnchorInfo();
2828
int value; /* weighted value */
29-
final byte map[] = new byte[Config.CHAR_TABLE_SIZE];
29+
final byte[] map = new byte[Config.CHAR_TABLE_SIZE];
3030

3131
void clear() {
3232
mmd.clear();
@@ -99,7 +99,7 @@ void altMerge(OptMapInfo other, Encoding enc) {
9999
anchor.altMerge(other.anchor);
100100
}
101101

102-
static final short ByteValTable[] = {
102+
static final short[] ByteValTable = {
103103
5, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 10, 1, 1,
104104
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
105105
12, 4, 7, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,

src/org/joni/Parser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected Parser(Regex regex, Syntax syntax, byte[]bytes, int p, int end, WarnCa
6262

6363
private static final int POSIX_BRACKET_NAME_MIN_LEN = 4;
6464
private static final int POSIX_BRACKET_CHECK_LIMIT_LENGTH = 20;
65-
private static final byte BRACKET_END[] = ":]".getBytes();
65+
private static final byte[] BRACKET_END = ":]".getBytes();
6666
private boolean parsePosixBracket(CClassNode cc, CClassNode ascCc) {
6767
mark();
6868

@@ -309,7 +309,7 @@ private CClassNode parseCharClass(ObjPtr<CClassNode> ascNode) {
309309
break;
310310

311311
case CC_CC_OPEN: /* [ */
312-
ObjPtr<CClassNode> ascPtr = new ObjPtr<CClassNode>();
312+
ObjPtr<CClassNode> ascPtr = new ObjPtr<>();
313313
CClassNode acc = parseCharClass(ascPtr);
314314
cc.or(acc, env);
315315
if (ascPtr.p != null) {
@@ -817,7 +817,7 @@ private Node parseExp(TokenType term) {
817817
break;
818818

819819
case CC_OPEN: {
820-
ObjPtr<CClassNode> ascPtr = new ObjPtr<CClassNode>();
820+
ObjPtr<CClassNode> ascPtr = new ObjPtr<>();
821821
CClassNode cc = parseCharClass(ascPtr);
822822
int code = cc.isOneChar();
823823
if (code != -1) return parseStringLoop(StringNode.fromCodePoint(code, enc), group);

src/org/joni/Regex.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.joni.exception.ErrorMessages;
3939
import org.joni.exception.InternalException;
4040
import org.joni.exception.ValueException;
41-
import org.joni.Config;
4241

4342
public final class Regex {
4443
int[] code; /* compiled pattern */
@@ -237,7 +236,7 @@ void nameAdd(byte[]name, int nameP, int nameEnd, int backRef, Syntax syntax) {
237236

238237
NameEntry e = null;
239238
if (nameTable == null) {
240-
nameTable = new BytesHash<NameEntry>(); // 13, oni defaults to 5
239+
nameTable = new BytesHash<>(); // 13, oni defaults to 5
241240
} else {
242241
e = nameFind(name, nameP, nameEnd);
243242
}

src/org/joni/ScanEnvironment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class ScanEnvironment {
4444

4545
int numNamed; // USE_NAMED_GROUP
4646

47-
public EncloseNode memNodes[];
47+
public EncloseNode[] memNodes;
4848

4949
// USE_COMBINATION_EXPLOSION_CHECK
5050
int numCombExpCheck;
@@ -54,7 +54,7 @@ public final class ScanEnvironment {
5454
private int warningsFlag;
5555

5656
int numPrecReadNotNodes;
57-
Node precReadNotNodes[];
57+
Node[] precReadNotNodes;
5858

5959
ScanEnvironment(Regex regex, Syntax syntax, WarnCallback warnings) {
6060
this.syntax = syntax;

0 commit comments

Comments
 (0)