Skip to content
Open
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 @@ -28,6 +28,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Serializable;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.Map;

Expand Down Expand Up @@ -66,19 +67,25 @@ public final class ReferenceMapper implements IReferenceMapper, Serializable {
* Passthrough mapper, used as failover
*/
public static final ReferenceMapper DEFAULT_MAPPER = new ReferenceMapper(true, "invalid");

/**
* Refmaps which were already read by {@link #readShared}, keyed by
* resource path
*/
private static final Map<String, ReferenceMapper> cache = new HashMap<String, ReferenceMapper>();

/**
* "Default" mappings. The set of mappings to use as "default" is specified
* by the AP. Each entry is keyed by the owning mixin, with the value map
* containing the actual remappings for each owner
*/
private final Map<String, Map<String, String>> mappings = Maps.newTreeMap();
private final Map<String, Map<String, String>> mappings;

/**
* All mapping sets, keyed by environment type, eg. "notch", "searge". The
* format of each map within this map is the same as for {@link #mappings}
*/
private final Map<String, Map<String, Map<String, String>>> data = Maps.newTreeMap();
private final Map<String, Map<String, Map<String, String>>> data;

/**
* True if this refmap cannot be written. Only true for the
Expand Down Expand Up @@ -111,6 +118,21 @@ public ReferenceMapper() {
private ReferenceMapper(boolean readOnly, String resource) {
this.readOnly = readOnly;
this.resource = resource;
this.mappings = Maps.newTreeMap();
this.data = Maps.newTreeMap();
}

/**
* Create a refmap which shares the mappings of an existing refmap
* but has its own context, used by {@link #readShared}.
*
* @param shared refmap to share mappings with
*/
private ReferenceMapper(ReferenceMapper shared) {
this.readOnly = shared.readOnly;
this.resource = shared.resource;
this.mappings = shared.mappings;
this.data = shared.data;
}

/* (non-Javadoc)
Expand Down Expand Up @@ -275,6 +297,26 @@ public static ReferenceMapper read(String resourcePath) {
return ReferenceMapper.DEFAULT_MAPPER;
}

/**
* Read a refmap from the specified resource, reusing cached mappings if
* available. The returned refmap object has its own context but shares its
* mappings.
*
* @param resourcePath Resource to read from
* @return new refmap or {@link #DEFAULT_MAPPER} if reading fails
*/
public static ReferenceMapper readShared(String resourcePath) {
ReferenceMapper shared = ReferenceMapper.cache.get(resourcePath);
if (shared == null) {
shared = ReferenceMapper.read(resourcePath);
if (shared.isDefault()) {
return shared;
}
ReferenceMapper.cache.put(resourcePath, shared);
}
return new ReferenceMapper(shared);
}

/**
* Read a new refmap instance from the specified reader
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ void onSelect() {
}
}

this.refMapper = ReferenceMapper.read(this.refMapperConfig);
this.refMapper = ReferenceMapper.readShared(this.refMapperConfig);

if (!suppressRefMapWarning && this.refMapper.isDefault() && !this.env.getOption(Option.DISABLE_REFMAP)) {
this.logger.warn("Reference map '{}' for {} could not be read. If this is a development environment you can ignore this message",
Expand Down
Loading