summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTairu Wang <tairuw@google.com>2024-02-20 00:12:20 +0000
committerPo-Chun Lee <pochunlee@google.com>2024-02-20 19:25:34 +0000
commit8726e1cf9b7dc4245751160e0c328ae45cd79a83 (patch)
tree7f62760010e49b72a21810e6063cf9ea29a11918
parent2bb7b2a4be3d5ab39fa8b162a28442da37c0691f (diff)
downloadIwlan-8726e1cf9b7dc4245751160e0c328ae45cd79a83.tar.gz
Reuse Pattern instance to improve performance
To improve the performance, explicitly compile the regular expression into a Pattern instance (which is immutable) as part of class initialization, cache it, and reuse the same instance for every invocation. Bug: 325342963 Test: atest IwlanTests (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a3dd84ad72786d8767d6b988f46a468404e117cd) Merged-In: Icaed3cfbfad3b47ea3230ce3c638b32d33914a90 Change-Id: Icaed3cfbfad3b47ea3230ce3c638b32d33914a90
-rw-r--r--src/com/google/android/iwlan/epdg/EpdgSelector.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/com/google/android/iwlan/epdg/EpdgSelector.java b/src/com/google/android/iwlan/epdg/EpdgSelector.java
index 3db6ac2..3590a7e 100644
--- a/src/com/google/android/iwlan/epdg/EpdgSelector.java
+++ b/src/com/google/android/iwlan/epdg/EpdgSelector.java
@@ -68,6 +68,7 @@ import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class EpdgSelector {
@@ -101,6 +102,7 @@ public class EpdgSelector {
private static final int PCO_IPV6_LEN = 16; // 16 bytes for IPv6 address in PCO data.
private static final String NO_DOMAIN = "NO_DOMAIN";
+ private static final Pattern PLMN_PATTERN = Pattern.compile("\\d{5,6}");
BlockingQueue<Runnable> dnsResolutionQueue;
@@ -1388,6 +1390,6 @@ public class EpdgSelector {
* @return True if the PLMN identifier is valid, false otherwise.
*/
private static boolean isValidPlmn(String plmn) {
- return plmn != null && plmn.matches("\\d{5,6}");
+ return plmn != null && PLMN_PATTERN.matcher(plmn).matches();
}
}