Skip to content

Commit

Permalink
[43] Only call getPackageForURI on URI-like paths
Browse files Browse the repository at this point in the history
This avoids creating thousands of PackageNotFoundError instances when
resolving "normal" inter-document references which do not refer to
EPackages via nsURIs.

PackageNotFoundError are much cheaper to create than the previously
used PackageNotFoundException, but that's still a lot of garbage
instances to create, add into the resource.getErrors() list and never
use (or even clear).

In addition, in the context of Sirius Web, every instance will have
its own duplicate string representation of the failed "package" URI
because we get it from EObjectIDManager.getOrCreateId(EObject) which
invokes UUID.toString() and allocates a new (identical) String each
time.

Bug: #43
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid committed Jun 24, 2024
1 parent 6c48ff9 commit af8b224
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
*/
public class GsonEObjectDeserializer implements JsonDeserializer<List<EObject>> {

private static final char SCHEME_SEPARATOR = ':';

/**
* The JsonHelper.
*/
Expand Down Expand Up @@ -540,15 +542,13 @@ private void deserializeSingleNonContainmentEReference(EReference eReference, Js
this.helper.setValue(eObject, eReference, object);
}
} else {
String resourceURIPath = id.substring(0, index); // The URI of the resource where I can find
// the EObject
EPackage ePackage = this.getPackageForURI(resourceURIPath); // return an EPackage only if the
// URI represent an EPackage
Resource packageResource = null;
String resourceURIPath = id.substring(0, index);
EObject object = null;
if (ePackage != null) {
packageResource = ePackage.eResource();
object = packageResource.getEObject(fragmentEMF);
if (resourceURIPath.indexOf(SCHEME_SEPARATOR) != -1) {
EPackage ePackage = this.getPackageForURI(resourceURIPath);
if (ePackage != null) {
object = ePackage.eResource().getEObject(fragmentEMF);
}
} else {
object = this.createProxyEObject(id, qualifiedType, eReference);
}
Expand Down Expand Up @@ -605,7 +605,7 @@ private EObject createProxyEObject(String id, String qualifiedType, EReference e
/**
* Resolves a type from a qualified name (e.g. "flow:System") into the corresponding EClass (or null) using the
* resource set's package registry.
*
*
* @param qualifiedType
* the qualified name of the type to resolve.
* @return the corresponding EClass, or null.
Expand Down Expand Up @@ -701,12 +701,12 @@ private void deserializeMultipleNonContainmentEReference(EReference eReference,
}
} else {
String resourceURIPath = id.substring(0, index);
EPackage ePackage = this.getPackageForURI(resourceURIPath);
Resource packageResource = null;
EObject object = null;
if (ePackage != null) {
packageResource = ePackage.eResource();
object = packageResource.getEObject(fragmentEMF);
if (resourceURIPath.indexOf(SCHEME_SEPARATOR) != -1) {
EPackage ePackage = this.getPackageForURI(resourceURIPath);
if (ePackage != null) {
object = ePackage.eResource().getEObject(fragmentEMF);
}
} else {
object = this.createProxyEObject(id, qualifiedType, eReference);
}
Expand Down

0 comments on commit af8b224

Please sign in to comment.