Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intern type names #1285

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected final void check() {

@JsonCreator
public static ConjurePackage of(String name) {
return ImmutableConjurePackage.builder().name(name).build();
return ImmutableConjurePackage.builder().name(Names.intern(name)).build();
}

public static ConjurePackage of(Iterable<String> components) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ protected final void check() {

@JsonCreator
public static ErrorCode of(String name) {
return ImmutableErrorCode.builder().name(name).build();
return ImmutableErrorCode.builder().name(Names.intern(name)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ protected final void check() {

@JsonCreator
public static ErrorNamespace of(String name) {
return ImmutableErrorNamespace.builder().name(name).build();
return ImmutableErrorNamespace.builder().name(Names.intern(name)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected CaseConverter.Case nameCase() {

@JsonCreator
public static FieldName of(String name) {
return ImmutableFieldName.builder().name(name).build();
return ImmutableFieldName.builder().name(Names.intern(name)).build();
}

/** Converts this {@link FieldName} to a {@link FieldName} with the given case. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* (c) Copyright 2022 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.conjure.parser.types.names;

import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import javax.annotation.Nullable;

final class Names {
private static final Interner<String> internedNames = Interners.newWeakInterner();

private Names() {}

static String intern(@Nullable String name) {
return (name == null) ? null : internedNames.intern(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ protected final void check() {

@JsonCreator
public static Namespace of(String name) {
return ImmutableNamespace.builder().name(name).build();
return ImmutableNamespace.builder().name(Names.intern(name)).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ protected final void check() {

@JsonCreator
public static TypeName of(String name) {
return ImmutableTypeName.builder().name(name).build();
return ImmutableTypeName.builder().name(Names.intern(name)).build();
}
}