You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2005/12/02 15:41:02 UTC
svn commit: r351738 -
/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
Author: djd
Date: Fri Dec 2 06:40:59 2005
New Revision: 351738
URL: http://svn.apache.org/viewcvs?rev=351738&view=rev
Log:
DERBY-740 Optimize the cast method to not generate checkcast instructions when
the cast class name exactly matches the current type of the top word on the stack.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java?rev=351738&r1=351737&r2=351738&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java Fri Dec 2 06:40:59 2005
@@ -629,10 +629,33 @@
}
public void cast(String className) {
- Type ct = cb.factory.type(className);
- Type tbc = popStack();
-
+
+ // Perform a simple optimization to not
+ // insert a checkcast when the classname
+ // of the cast exactly matches the type name
+ // currently on the stack.
+ // This can reduce the amount of generated code.
+ // This compiler/class generator does not load
+ // classes to check relationships or any other
+ // information. Thus other optimizations where a cast
+ // is not required are not implemented.
+ Type tbc = stackTypes[stackTypeOffset - 1];
+
short sourceType = tbc.vmType();
+
+ if (sourceType == BCExpr.vm_reference)
+ {
+ // Simple optimize step
+ if (className.equals(tbc.javaName()))
+ {
+ // do nothing, exact matching type
+ return;
+ }
+ }
+
+ Type ct = cb.factory.type(className);
+ popStack();
+
short targetType = ct.vmType();
if (SanityManager.DEBUG) {