On 08/05/2019 17:16, Christopher Schultz wrote: > All, > > While working on the sort-file-listing enhancement over the weekend, I > looked in the Tomcat code to see if we already had a method to split a > string by a single character. The closest method I found was > org.pache.jasper.compiler.JspUtil which splits on a string, so I > rejected it as being a bit too general-purpose for my needs. > > But it got me looking into the implementation of the method, and it > looks a little sketchy. > > First, it uses a java.util.Vector. Yep, a Vector. Remember those? > Synchronized everything? The Vector is not used outside of the method > at all -- it's just local and temporary. So, the obvious conclusion is > that it should be changed to ArrayList, right? > > But, modern JVMs are fairly good at (a) processing contention-less > locks more quickly and (b) identifying objects which cannot possibly > have lock-contention and simply skipping the locking. > > What's the right move in these cases? Should we change Vector -> > ArrayList and "help-out" the compiler and runtime, or should we leave > the code alone because "it's fine"? > > Similar arguments can be made for using StringBuilder over > StringBuffer, etc. > > WDYT?
I think the code is cleaner and easier to understand when the code matches the intention rather than when the code plus some expected compiler optimisation match the intention. So I'd say +1 to making these sorts of changes. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org