Don't create a new ParserImpl on each parser() call (#11255)

Motivation:

ParserImpl is stateless and so we can use the same instance multiple times

Modifications:

- Make constructor private
- Return the same instance all the time

Result:

Less object creation
This commit is contained in:
Norman Maurer 2021-05-14 15:19:04 +02:00
parent 747a686cd7
commit 605290f821

View File

@ -120,7 +120,7 @@ public final class HostsFileEntriesProvider {
* @return a new {@link HostsFileEntriesProvider.Parser}
*/
public static Parser parser() {
return new ParserImpl();
return ParserImpl.INSTANCE;
}
static final HostsFileEntriesProvider EMPTY =
@ -164,6 +164,12 @@ public final class HostsFileEntriesProvider {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Parser.class);
static final ParserImpl INSTANCE = new ParserImpl();
private ParserImpl() {
// singleton
}
@Override
public HostsFileEntriesProvider parse() throws IOException {
return parse(locateHostsFile(), Charset.defaultCharset());