Skip to content

Commit 605290f

Browse files
committed
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
1 parent 747a686 commit 605290f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

resolver/src/main/java/io/netty/resolver/HostsFileEntriesProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public interface Parser {
120120
* @return a new {@link HostsFileEntriesProvider.Parser}
121121
*/
122122
public static Parser parser() {
123-
return new ParserImpl();
123+
return ParserImpl.INSTANCE;
124124
}
125125

126126
static final HostsFileEntriesProvider EMPTY =
@@ -164,6 +164,12 @@ private static final class ParserImpl implements Parser {
164164

165165
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Parser.class);
166166

167+
static final ParserImpl INSTANCE = new ParserImpl();
168+
169+
private ParserImpl() {
170+
// singleton
171+
}
172+
167173
@Override
168174
public HostsFileEntriesProvider parse() throws IOException {
169175
return parse(locateHostsFile(), Charset.defaultCharset());

0 commit comments

Comments
 (0)