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:
parent
747a686cd7
commit
605290f821
@ -120,7 +120,7 @@ public final class HostsFileEntriesProvider {
|
|||||||
* @return a new {@link HostsFileEntriesProvider.Parser}
|
* @return a new {@link HostsFileEntriesProvider.Parser}
|
||||||
*/
|
*/
|
||||||
public static Parser parser() {
|
public static Parser parser() {
|
||||||
return new ParserImpl();
|
return ParserImpl.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static final HostsFileEntriesProvider EMPTY =
|
static final HostsFileEntriesProvider EMPTY =
|
||||||
@ -164,6 +164,12 @@ public final class HostsFileEntriesProvider {
|
|||||||
|
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Parser.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Parser.class);
|
||||||
|
|
||||||
|
static final ParserImpl INSTANCE = new ParserImpl();
|
||||||
|
|
||||||
|
private ParserImpl() {
|
||||||
|
// singleton
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HostsFileEntriesProvider parse() throws IOException {
|
public HostsFileEntriesProvider parse() throws IOException {
|
||||||
return parse(locateHostsFile(), Charset.defaultCharset());
|
return parse(locateHostsFile(), Charset.defaultCharset());
|
||||||
|
Loading…
Reference in New Issue
Block a user