Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-02-21 03:23:34 -0500
committerEike Stepper2013-02-21 03:23:34 -0500
commit858f85078a6567ed5dfec0306f6671231a4c891d (patch)
tree5b71922c120f706649baf8642920991f109effda
parentccc143cdbf937af334cb50a69582bb3f8899758e (diff)
downloadcdo-858f85078a6567ed5dfec0306f6671231a4c891d.tar.gz
cdo-858f85078a6567ed5dfec0306f6671231a4c891d.tar.xz
cdo-858f85078a6567ed5dfec0306f6671231a4c891d.zip
[401397] Optimize CDOModelUtil
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401397
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelConstants.java32
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java148
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/model/CDOPackageRegistryImpl.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java15
4 files changed, 121 insertions, 79 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelConstants.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelConstants.java
index 6b5137b55e..363b584af7 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelConstants.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelConstants.java
@@ -23,77 +23,77 @@ public interface CDOModelConstants
/**
* @since 4.2
*/
- public static final String RESOURCE_FOLDER_NODES_REFERENCE = "nodes".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_FOLDER_NODES_REFERENCE = "nodes"; //$NON-NLS-1$
/**
* @since 4.2
*/
- public static final String RESOURCE_NODE_FOLDER_REFERENCE = "folder".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_NODE_FOLDER_REFERENCE = "folder"; //$NON-NLS-1$
- public static final String RESOURCE_NODE_NAME_ATTRIBUTE = "name".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_NODE_NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String CORE_PACKAGE_URI = "http://www.eclipse.org/emf/2002/Ecore".intern(); //$NON-NLS-1$
+ public static final String CORE_PACKAGE_URI = "http://www.eclipse.org/emf/2002/Ecore"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String ROOT_CLASS_NAME = "EObject".intern(); //$NON-NLS-1$
+ public static final String ROOT_CLASS_NAME = "EObject"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String RESOURCE_PACKAGE_URI = "http://www.eclipse.org/emf/CDO/Eresource/4.0.0".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_PACKAGE_URI = "http://www.eclipse.org/emf/CDO/Eresource/4.0.0"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String RESOURCE_NODE_CLASS_NAME = "CDOResourceNode".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_NODE_CLASS_NAME = "CDOResourceNode"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String RESOURCE_FOLDER_CLASS_NAME = "CDOResourceFolder".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_FOLDER_CLASS_NAME = "CDOResourceFolder"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String RESOURCE_CLASS_NAME = "CDOResource".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_CLASS_NAME = "CDOResource"; //$NON-NLS-1$
/**
* @since 4.2
*/
- public static final String RESOURCE_LEAF_CLASS_NAME = "CDOResourceLeaf".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_LEAF_CLASS_NAME = "CDOResourceLeaf"; //$NON-NLS-1$
/**
* @since 4.2
*/
- public static final String RESOURCE_FILE_CLASS_NAME = "CDOFileResource".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_FILE_CLASS_NAME = "CDOFileResource"; //$NON-NLS-1$
/**
* @since 4.2
*/
- public static final String RESOURCE_BINARY_FILE_CLASS_NAME = "CDOBinaryResource".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_BINARY_FILE_CLASS_NAME = "CDOBinaryResource"; //$NON-NLS-1$
/**
* @since 4.2
*/
- public static final String RESOURCE_TEXT_FILE_CLASS_NAME = "CDOTextResource".intern(); //$NON-NLS-1$
+ public static final String RESOURCE_TEXT_FILE_CLASS_NAME = "CDOTextResource"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String TYPES_PACKAGE_URI = "http://www.eclipse.org/emf/CDO/Etypes/4.0.0".intern(); //$NON-NLS-1$
+ public static final String TYPES_PACKAGE_URI = "http://www.eclipse.org/emf/CDO/Etypes/4.0.0"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String BLOB_CLASS_NAME = "Blob".intern(); //$NON-NLS-1$
+ public static final String BLOB_CLASS_NAME = "Blob"; //$NON-NLS-1$
/**
* @since 4.0
*/
- public static final String CLOB_CLASS_NAME = "Clob".intern(); //$NON-NLS-1$
+ public static final String CLOB_CLASS_NAME = "Clob"; //$NON-NLS-1$
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
index 04cf3c5f2d..4d82751cbc 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOModelUtil.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.internal.common.bundle.OM;
import org.eclipse.emf.cdo.internal.common.messages.Messages;
import org.eclipse.emf.cdo.internal.common.model.CDOClassInfoImpl;
import org.eclipse.emf.cdo.internal.common.model.CDOPackageInfoImpl;
+import org.eclipse.emf.cdo.internal.common.model.CDOPackageRegistryImpl;
import org.eclipse.emf.cdo.internal.common.model.CDOPackageUnitImpl;
import org.eclipse.emf.cdo.internal.common.model.CDOTypeImpl;
@@ -117,8 +118,13 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isCorePackage(EPackage ePackage)
{
- String nsURI = ePackage.getNsURI().intern();
- return nsURI == CORE_PACKAGE_URI;
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[0] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[0] == ePackage;
+ }
+
+ String nsURI = ePackage.getNsURI();
+ return CORE_PACKAGE_URI.equals(nsURI);
}
/**
@@ -126,10 +132,15 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isRoot(EClass eClass)
{
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[1] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[1] == eClass;
+ }
+
if (isCorePackage(eClass.getEPackage()))
{
- String name = eClass.getName().intern();
- return ROOT_CLASS_NAME == name;
+ String name = eClass.getName();
+ return ROOT_CLASS_NAME.equals(name);
}
return false;
@@ -140,8 +151,13 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isResourcePackage(EPackage ePackage)
{
- String nsURI = ePackage.getNsURI().intern();
- return nsURI == RESOURCE_PACKAGE_URI;
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[2] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[2] == ePackage;
+ }
+
+ String nsURI = ePackage.getNsURI();
+ return RESOURCE_PACKAGE_URI.equals(nsURI);
}
/**
@@ -149,10 +165,15 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isResource(EClass eClass)
{
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[3] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[3] == eClass;
+ }
+
if (isResourcePackage(eClass.getEPackage()))
{
- String name = eClass.getName().intern();
- return name == RESOURCE_CLASS_NAME;
+ String name = eClass.getName();
+ return RESOURCE_CLASS_NAME.equals(name);
}
return false;
@@ -163,10 +184,15 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isResourceFolder(EClass eClass)
{
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[4] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[4] == eClass;
+ }
+
if (isResourcePackage(eClass.getEPackage()))
{
- String name = eClass.getName().intern();
- return name == RESOURCE_FOLDER_CLASS_NAME;
+ String name = eClass.getName();
+ return RESOURCE_FOLDER_CLASS_NAME.equals(name);
}
return false;
@@ -177,15 +203,7 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isResourceNode(EClass eClass)
{
- if (isResourcePackage(eClass.getEPackage()))
- {
- String name = eClass.getName().intern();
- return name == RESOURCE_NODE_CLASS_NAME || name == RESOURCE_LEAF_CLASS_NAME || name == RESOURCE_CLASS_NAME
- || name == RESOURCE_CLASS_NAME || name == RESOURCE_CLASS_NAME || name == RESOURCE_CLASS_NAME
- || name == RESOURCE_FOLDER_CLASS_NAME;
- }
-
- return false;
+ return isResourcePackage(eClass.getEPackage());
}
/**
@@ -193,8 +211,13 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isTypesPackage(EPackage ePackage)
{
- String nsURI = ePackage.getNsURI().intern();
- return nsURI == TYPES_PACKAGE_URI;
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[5] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[5] == ePackage;
+ }
+
+ String nsURI = ePackage.getNsURI();
+ return TYPES_PACKAGE_URI.equals(nsURI);
}
/**
@@ -202,8 +225,7 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isSystemPackage(EPackage ePackage)
{
- String nsURI = ePackage.getNsURI().intern();
- return nsURI == CORE_PACKAGE_URI || nsURI == RESOURCE_PACKAGE_URI || nsURI == TYPES_PACKAGE_URI;
+ return isCorePackage(ePackage) || isResourcePackage(ePackage) || isTypesPackage(ePackage);
}
/**
@@ -211,10 +233,16 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static boolean isLob(EClassifier eClassifier)
{
+ if (CDOPackageRegistryImpl.SYSTEM_ELEMENTS[6] != null && CDOPackageRegistryImpl.SYSTEM_ELEMENTS[7] != null)
+ {
+ return CDOPackageRegistryImpl.SYSTEM_ELEMENTS[6] == eClassifier
+ || CDOPackageRegistryImpl.SYSTEM_ELEMENTS[7] == eClassifier;
+ }
+
if (isTypesPackage(eClassifier.getEPackage()))
{
- String name = eClassifier.getName().intern();
- return name == BLOB_CLASS_NAME || name == CLOB_CLASS_NAME;
+ String name = eClassifier.getName();
+ return BLOB_CLASS_NAME.equals(name) || CLOB_CLASS_NAME.equals(name);
}
return false;
@@ -230,7 +258,7 @@ public final class CDOModelUtil implements CDOModelConstants
return CDOType.FEATURE_MAP_ENTRY;
}
- return CDOModelUtil.getType(feature.getEType());
+ return getType(feature.getEType());
}
/**
@@ -385,92 +413,88 @@ public final class CDOModelUtil implements CDOModelConstants
*/
public static CDOType getTypeOfObject(Object object)
{
- if (object == null)
+ if (object == null || object instanceof CDOID || object instanceof CDORevision)
{
return CDOType.OBJECT;
}
- if (object.getClass() == BigDecimal.class || object instanceof BigDecimal)
+ Class<? extends Object> objectClass = object.getClass();
+ if (objectClass == String.class)
{
- return CDOType.BIG_DECIMAL;
- }
-
- if (object.getClass() == BigInteger.class || object instanceof BigInteger)
- {
- return CDOType.BIG_INTEGER;
+ return CDOType.STRING;
}
- if (object.getClass() == Boolean.class || object instanceof Boolean)
+ if (objectClass == Integer.class)
{
- return CDOType.BOOLEAN_OBJECT;
+ return CDOType.INTEGER_OBJECT;
}
- if (object.getClass() == Byte.class || object instanceof Byte)
+ if (objectClass == Long.class)
{
- return CDOType.BYTE_OBJECT;
+ return CDOType.LONG_OBJECT;
}
- if (object.getClass() == byte[].class || object instanceof byte[])
+ if (objectClass == Boolean.class)
{
- return CDOType.BYTE_ARRAY;
+ return CDOType.BOOLEAN_OBJECT;
}
- if (object.getClass() == Character.class || object instanceof Character)
+ if (objectClass == Character.class)
{
return CDOType.CHARACTER_OBJECT;
}
- if (object.getClass() == Date.class || object instanceof Date)
+ if (objectClass == Double.class)
{
- return CDOType.DATE;
+ return CDOType.DOUBLE_OBJECT;
}
- if (object.getClass() == Double.class || object instanceof Double)
+ if (objectClass == Float.class)
{
- return CDOType.DOUBLE_OBJECT;
+ return CDOType.FLOAT_OBJECT;
}
- if (object instanceof EEnumLiteral)
+ if (objectClass == Short.class)
{
- return CDOType.ENUM_LITERAL;
+ return CDOType.SHORT_OBJECT;
}
- if (object instanceof FeatureMap.Entry)
+ if (objectClass == Byte.class)
{
- return CDOType.FEATURE_MAP_ENTRY;
+ return CDOType.BYTE_OBJECT;
}
- if (object.getClass() == Float.class || object instanceof Float)
+ if (objectClass == byte[].class)
{
- return CDOType.FLOAT_OBJECT;
+ return CDOType.BYTE_ARRAY;
}
- if (object.getClass() == Integer.class || object instanceof Integer)
+ if (objectClass == Date.class || object instanceof Date)
{
- return CDOType.INTEGER_OBJECT;
+ return CDOType.DATE;
}
- if (object.getClass() == Long.class || object instanceof Long)
+ if (object instanceof EEnumLiteral)
{
- return CDOType.LONG_OBJECT;
+ return CDOType.ENUM_LITERAL;
}
- if (object.getClass() == Short.class || object instanceof Short)
+ if (objectClass == BigDecimal.class || object instanceof BigDecimal)
{
- return CDOType.SHORT_OBJECT;
+ return CDOType.BIG_DECIMAL;
}
- if (object.getClass() == String.class || object instanceof String)
+ if (objectClass == BigInteger.class || object instanceof BigInteger)
{
- return CDOType.STRING;
+ return CDOType.BIG_INTEGER;
}
- if (object instanceof CDOID || object instanceof CDORevision)
+ if (object instanceof FeatureMap.Entry)
{
- return CDOType.OBJECT;
+ return CDOType.FEATURE_MAP_ENTRY;
}
- throw new IllegalArgumentException("Object type " + object.getClass().getName() + " is not supported.");
+ throw new IllegalArgumentException("Object type " + objectClass.getName() + " is not supported.");
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/model/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/model/CDOPackageRegistryImpl.java
index 53ec50532d..67ee3803e9 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/model/CDOPackageRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/model/CDOPackageRegistryImpl.java
@@ -40,6 +40,7 @@ import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
@@ -57,10 +58,12 @@ import java.util.Set;
*/
public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements InternalCDOPackageRegistry
{
- private static final long serialVersionUID = 1L;
+ public static final EModelElement[] SYSTEM_ELEMENTS = new EModelElement[8];
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOPackageRegistryImpl.class);
+ private static final long serialVersionUID = 1L;
+
private static final boolean eagerInternalCaches = false;
private boolean replacingDescriptors;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index 1ac88dc1ad..4a19fa434e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -19,7 +19,10 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
+import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
+import org.eclipse.emf.cdo.etypes.EtypesPackage;
+import org.eclipse.emf.cdo.internal.common.model.CDOPackageRegistryImpl;
import org.eclipse.emf.cdo.session.CDOCollectionLoadingPolicy;
import org.eclipse.emf.cdo.session.CDORepositoryInfo;
import org.eclipse.emf.cdo.session.CDOSession;
@@ -61,6 +64,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.InternalEObject.EStore;
import org.eclipse.emf.ecore.resource.Resource;
@@ -90,6 +94,17 @@ public final class CDOUtil
static
{
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[0] = EcorePackage.eINSTANCE;
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[1] = EcorePackage.eINSTANCE.getEObject();
+
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[2] = EresourcePackage.eINSTANCE;
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[3] = EresourcePackage.eINSTANCE.getCDOResource();
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[4] = EresourcePackage.eINSTANCE.getCDOResourceFolder();
+
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[5] = EtypesPackage.eINSTANCE;
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[6] = EtypesPackage.eINSTANCE.getBlob();
+ CDOPackageRegistryImpl.SYSTEM_ELEMENTS[7] = EtypesPackage.eINSTANCE.getClob();
+
if (!OMPlatform.INSTANCE.isOSGiRunning())
{
registerResourceFactory(Resource.Factory.Registry.INSTANCE);

Back to the top