You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public String replaceAll(String regex, String replacement) {
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
}
String method 'replaceFirst' is implemented as:
public String replaceFirst(String regex, String replacement) {
return Pattern.compile(regex).matcher(this).replaceFirst(replacement);
}
These methods provide a convenience method for creating a Pattern using Pattern.compile(), The Pattern.compile() method is slow, and should be avoided. The best way to do this is to statically compile the Pattern, and use the matcher from the static compiled pattern. This could improve performance a lot when the String.replaceAll method or String.replaceFirst method is called in the wrong place. (i.e. in a for loop). The pattern will be compiled on every invocation of the replaceAll or replaceFirst method.
Find and replace the method replaceAll and replaceFirst and change them into static compiled Patterns.
@kad-vetteh Thanks for the proposal. Can you tell us a little more about the context when this will effect deegree at runtime? And of course any source code and runtime improvement is welcome. So, we will be happy, if you are preparing a pull request.
@tfr42 I have attached a draft pull request: #1639
I was looking in the code recently, and noticed the methods, feel free to try if it makes some difference.
String method 'replaceAll' is implemented as:
String method 'replaceFirst' is implemented as:
These methods provide a convenience method for creating a Pattern using Pattern.compile(), The Pattern.compile() method is slow, and should be avoided. The best way to do this is to statically compile the Pattern, and use the matcher from the static compiled pattern. This could improve performance a lot when the String.replaceAll method or String.replaceFirst method is called in the wrong place. (i.e. in a for loop). The pattern will be compiled on every invocation of the replaceAll or replaceFirst method.
Find and replace the method replaceAll and replaceFirst and change them into static compiled Patterns.
replaceAll Before (slow)
replaceAll After (improved performance)
replaceFirst Before (slow)
replaceFirst After (improved performance)
The text was updated successfully, but these errors were encountered: