Skip to content

Commit db3b8d0

Browse files
committed
Take a substring instead of using a regex
1 parent 1c63695 commit db3b8d0

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

  • src/main/java/com/maxmind/minfraud/request

src/main/java/com/maxmind/minfraud/request/Email.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.util.Collections;
1111
import java.util.HashMap;
1212
import java.util.Map;
13-
import java.util.regex.Matcher;
14-
import java.util.regex.Pattern;
1513

1614
/**
1715
* The email information for the transaction.
@@ -21,8 +19,6 @@ public final class Email extends AbstractModel {
2119
private final boolean hashAddress;
2220
private final String domain;
2321
private static final Map<String, String> typoDomains;
24-
private static final Pattern addressDashRegex;
25-
private static final Pattern addressPlusRegex;
2622

2723
static {
2824
HashMap<String, String> m = new HashMap<String, String>() {{
@@ -39,9 +35,6 @@ public final class Email extends AbstractModel {
3935
}};
4036

4137
typoDomains = Collections.unmodifiableMap(m);
42-
43-
addressDashRegex = Pattern.compile("\\A([^-]+)-.*\\z");
44-
addressPlusRegex = Pattern.compile("\\A([^+]+)\\+.*\\z");
4538
}
4639

4740
private Email(Email.Builder builder) {
@@ -175,15 +168,15 @@ private String cleanAddress(String address) {
175168

176169
domain = cleanDomain(domain);
177170

178-
Pattern p;
171+
int stopChar;
179172
if (domain.equals("yahoo.com")) {
180-
p = addressDashRegex;
173+
stopChar = '-';
181174
} else {
182-
p = addressPlusRegex;
175+
stopChar = '+';
183176
}
184-
Matcher m = p.matcher(localPart);
185-
if (m.find()) {
186-
localPart = m.replaceFirst(m.group(1));
177+
int stopCharIndex = localPart.indexOf(stopChar);
178+
if (stopCharIndex > 0) {
179+
localPart = localPart.substring(0, stopCharIndex);
187180
}
188181

189182
return localPart + "@" + domain;

0 commit comments

Comments
 (0)