nishantmehta opened a new pull request, #863:
URL: https://github.com/apache/commons-io/pull/863
## Summary
`FilenameUtils.isExtension(String, String)` returned
`getExtension(fileName).equals(extension)`, and the `String...` overload did
`Stream.of(extensions).anyMatch(getExtension(fileName)::equals)`. Both allocate
the extension **substring** (and the varargs form an extra `Stream` pipeline)
only to compare it — on a file-filtering path that returns a `boolean`.
This compares the extension region of `fileName` in place via
`String.regionMatches`, through a small private helper that mirrors
`getExtension(fileName).equals(extension)` exactly: `NOT_FOUND` is treated as
the empty extension and a `null` extension never matches, so all documented
cases — no-extension files, empty and null extensions, and empty entries in the
varargs form — are unchanged. The `String...` overload also drops the `Stream`
for a plain loop.
## Measurement
ThreadMXBean allocation driver, 200k warmed ops,
`"/home/user/docs/report.final.pdf"`:
| call | before | after |
|------|--------|-------|
| `isExtension(s, "pdf")` | 48 B/op | 0 B/op |
| `isExtension(s, "doc", "pdf")` | 175 B/op | 0 B/op |
## Testing
`FilenameUtilsTest` passes unchanged (41 tests), including the existing null
/ empty-extension / varargs edge cases (`isExtension("file", "")`,
`isExtension("file", "rtf", "")`, the null-char injection test, etc.).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]