You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2018/01/05 18:38:58 UTC
[17/19] flink git commit: [hotfix] [core] Pre-compile regex pattern
in Path class
[hotfix] [core] Pre-compile regex pattern in Path class
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/a49f0378
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/a49f0378
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/a49f0378
Branch: refs/heads/master
Commit: a49f0378c3ad7c9b02ea3a94e44e73e4dcbeafa3
Parents: 1d38e0b
Author: Stephan Ewen <se...@apache.org>
Authored: Wed Dec 13 15:07:52 2017 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Fri Jan 5 19:38:07 2018 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/flink/core/fs/Path.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/a49f0378/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/core/fs/Path.java b/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
index 6398aa8..b463fd9 100644
--- a/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
+++ b/flink-core/src/main/java/org/apache/flink/core/fs/Path.java
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.regex.Pattern;
/**
* Names a file or directory in a {@link FileSystem}. Path strings use slash as
@@ -59,6 +60,9 @@ public class Path implements IOReadableWritable, Serializable {
*/
public static final String CUR_DIR = ".";
+ /** A pre-compiled regex/state-machine to match the windows drive pattern. */
+ private static final Pattern WINDOWS_ROOT_DIR_REGEX = Pattern.compile("/\\p{Alpha}+:/");
+
/**
* The internal representation of the path, a hierarchical URI.
*/
@@ -262,9 +266,9 @@ public class Path implements IOReadableWritable, Serializable {
path = path.replaceAll("/+", "/");
// remove tailing separator
- if (!path.equals(SEPARATOR) && // UNIX root path
- !path.matches("/\\p{Alpha}+:/") && // Windows root path
- path.endsWith(SEPARATOR)) {
+ if (path.endsWith(SEPARATOR) &&
+ !path.equals(SEPARATOR) && // UNIX root path
+ !WINDOWS_ROOT_DIR_REGEX.matcher(path).matches()) { // Windows root path)
// remove tailing slash
path = path.substring(0, path.length() - SEPARATOR.length());