Reputation: 5676
given following simple example code
rawData.matches(".*[a-zA-Z\\-].*")
I have two possibilities of refactoring:
1) refactoring into a variable
2) refactoring into a function
Is there any performance impact on (2)?
AFAIK the JVM inlines all function calls and it should have no impact.
Upvotes: 0
Views: 56
Reputation: 3186
If you use this call multiple times then the best thing would probably be to get rid of the magic String
literal in the argument.
Other than that the performance improvements are probably miniscule and unimportant and it's all down to preference on whether or not you want to wrap it in another function.
Also try not to look into premature optimization too much.
Upvotes: 1