Skip to content

Commit cc067be

Browse files
committed
Tweaks to Netflix interning PR - naming etc..
1 parent 063485d commit cc067be

4 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/main/java/graphql/language/Field.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import graphql.Internal;
77
import graphql.PublicApi;
88
import graphql.collect.ImmutableKit;
9-
import graphql.util.FieldNameInterner;
9+
import graphql.util.Interning;
1010
import graphql.util.TraversalControl;
1111
import graphql.util.TraverserContext;
1212

@@ -51,8 +51,8 @@ protected Field(String name,
5151
IgnoredChars ignoredChars,
5252
Map<String, String> additionalData) {
5353
super(sourceLocation, comments, ignoredChars, additionalData);
54-
this.name = name == null ? null : FieldNameInterner.intern(name);
55-
this.alias = alias == null ? null : FieldNameInterner.intern(alias);
54+
this.name = name == null ? null : Interning.intern(name);
55+
this.alias = alias;
5656
this.arguments = ImmutableList.copyOf(arguments);
5757
this.directives = ImmutableList.copyOf(directives);
5858
this.selectionSet = selectionSet;

src/main/java/graphql/schema/GraphQLFieldDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import graphql.Internal;
77
import graphql.PublicApi;
88
import graphql.language.FieldDefinition;
9-
import graphql.util.FieldNameInterner;
9+
import graphql.util.Interning;
1010
import graphql.util.TraversalControl;
1111
import graphql.util.TraverserContext;
1212

@@ -62,7 +62,7 @@ private GraphQLFieldDefinition(String name,
6262
assertValidName(name);
6363
assertNotNull(type, () -> "type can't be null");
6464
assertNotNull(arguments, () -> "arguments can't be null");
65-
this.name = FieldNameInterner.intern(name);
65+
this.name = Interning.intern(name);
6666
this.description = description;
6767
this.originalType = type;
6868
this.dataFetcherFactory = dataFetcherFactory;

src/main/java/graphql/util/FieldNameInterner.java

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package graphql.util;
2+
3+
import com.google.common.collect.Interner;
4+
import com.google.common.collect.Interners;
5+
import graphql.Internal;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
/**
9+
* Interner allowing object-identity comparison of key entities like field names. This is useful on hotspot
10+
* areas like the engine where we look up field names a lot inside maps, and those maps use object identity first
11+
* inside the key lookup code.
12+
*/
13+
@Internal
14+
public class Interning {
15+
16+
private Interning() {
17+
}
18+
19+
private static final Interner<String> INTERNER = Interners.newWeakInterner();
20+
21+
public static @NotNull String intern(@NotNull String name) {
22+
return INTERNER.intern(name);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)