You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Stefan Ackermann <st...@gmx.ch> on 2008/02/04 14:09:41 UTC

use isPrimitive() instead of comparing the string to a list of primitives

Hi

This is not really a problem, but I noticed that on line 1612 of  
AbstractIOBuffer in the current trunk determining whether a class is  
primitive could be done nicer and faster with this:
Replace:
                     String className = desc.getName();
                     if (primitiveTypeNames.contains(className)) {
with:
          		  if (desc.forClass().isPrimitive()) {
isPrimitive is a native Function. Also if a new primitive Type were to be  
added, the code would still work.
It should do the same, I looked it up in the code.

Keep it up!
Stivo

-- 
Stefan Ackermann,
stivo@gmx.ch

Re: use isPrimitive() instead of comparing the string to a list of primitives

Posted by Stivo <sp...@gmx.net>.
There is a first time for everything :)
I did, 
https://issues.apache.org/jira/browse/DIRMINA-529

Greetz,
Stivo


Maarten Bosteels wrote:
> 
> Could you create a JIRA ticket and attach your patch to it ?
> And don't forget to click the radio button that says
> 'Grant license to ASF for inclusion in ASF works (as per the Apache
> Software
> License §5)'
> 
> Thanks
> Maarten
> 
-- 
View this message in context: http://www.nabble.com/use-isPrimitive%28%29-instead-of-comparing-the-string-to-a-list-of-primitives-tp15267788s16868p15331579.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: use isPrimitive() instead of comparing the string to a list of primitives

Posted by Maarten Bosteels <mb...@gmail.com>.
Could you create a JIRA ticket and attach your patch to it ?
And don't forget to click the radio button that says
'Grant license to ASF for inclusion in ASF works (as per the Apache Software
License §5)'

Thanks
Maarten

On Feb 7, 2008 10:25 AM, Maarten Bosteels <mb...@gmail.com> wrote:

> Hi Stivo,
>
> Thanks for the patch !
> I will have a look at it.
>
> Maarten
>
>
> On Feb 7, 2008 9:56 AM, Stivo <sp...@gmx.net> wrote:
>
> >
> > I figured out how to make a patch so here goes.
> > I ran the maven test with it, and it ran fine.
> >
> > Index: C:/Users/Stivo/workspacenew/mina
> > trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
> > ===================================================================
> > --- C:/Users/Stivo/workspacenew/mina
> > trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
> > (revision
> > 619305)
> > +++ C:/Users/Stivo/workspacenew/mina
> > trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java   (working
> > copy)
> > @@ -306,20 +306,6 @@
> >         return newCapacity;
> >     }
> >
> > -    protected static final Set<String> primitiveTypeNames = new
> > HashSet<String>();
> > -
> > -    static {
> > -        primitiveTypeNames.add("void");
> > -        primitiveTypeNames.add("boolean");
> > -        primitiveTypeNames.add("byte");
> > -        primitiveTypeNames.add("char");
> > -        primitiveTypeNames.add("short");
> > -        primitiveTypeNames.add("int");
> > -        primitiveTypeNames.add("long");
> > -        primitiveTypeNames.add("float");
> > -        primitiveTypeNames.add("double");
> > -    }
> > -
> >     /**
> >      * Creates a new instance.  This is an empty constructor.
> >      */
> > Index: C:/Users/Stivo/workspacenew/mina
> > trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
> > ===================================================================
> > --- C:/Users/Stivo/workspacenew/mina
> > trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
> > (revision 619305)
> > +++ C:/Users/Stivo/workspacenew/mina
> > trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
> > (working copy)
> > @@ -1608,8 +1608,7 @@
> >                 @Override
> >                 protected void writeClassDescriptor(ObjectStreamClass
> > desc)
> >                         throws IOException {
> > -                    String className = desc.getName();
> > -                    if (primitiveTypeNames.contains(className)) {
> > +                       if (desc.forClass().isPrimitive()) {
> >                         write(0);
> >                         super.writeClassDescriptor(desc);
> >                     } else {
> >
> > --
> > View this message in context:
> > http://www.nabble.com/use-isPrimitive%28%29-instead-of-comparing-the-string-to-a-list-of-primitives-tp15267788s16868p15329675.html
> > Sent from the Apache MINA Support Forum mailing list archive at
> > Nabble.com.
> >
> >
>

Re: use isPrimitive() instead of comparing the string to a list of primitives

Posted by Maarten Bosteels <mb...@gmail.com>.
Hi Stivo,

Thanks for the patch !
I will have a look at it.

Maarten

On Feb 7, 2008 9:56 AM, Stivo <sp...@gmx.net> wrote:

>
> I figured out how to make a patch so here goes.
> I ran the maven test with it, and it ran fine.
>
> Index: C:/Users/Stivo/workspacenew/mina
> trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
> ===================================================================
> --- C:/Users/Stivo/workspacenew/mina
> trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java   (revision
> 619305)
> +++ C:/Users/Stivo/workspacenew/mina
> trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java   (working
> copy)
> @@ -306,20 +306,6 @@
>         return newCapacity;
>     }
>
> -    protected static final Set<String> primitiveTypeNames = new
> HashSet<String>();
> -
> -    static {
> -        primitiveTypeNames.add("void");
> -        primitiveTypeNames.add("boolean");
> -        primitiveTypeNames.add("byte");
> -        primitiveTypeNames.add("char");
> -        primitiveTypeNames.add("short");
> -        primitiveTypeNames.add("int");
> -        primitiveTypeNames.add("long");
> -        primitiveTypeNames.add("float");
> -        primitiveTypeNames.add("double");
> -    }
> -
>     /**
>      * Creates a new instance.  This is an empty constructor.
>      */
> Index: C:/Users/Stivo/workspacenew/mina
> trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
> ===================================================================
> --- C:/Users/Stivo/workspacenew/mina
> trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
> (revision 619305)
> +++ C:/Users/Stivo/workspacenew/mina
> trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
> (working copy)
> @@ -1608,8 +1608,7 @@
>                 @Override
>                 protected void writeClassDescriptor(ObjectStreamClass
> desc)
>                         throws IOException {
> -                    String className = desc.getName();
> -                    if (primitiveTypeNames.contains(className)) {
> +                       if (desc.forClass().isPrimitive()) {
>                         write(0);
>                         super.writeClassDescriptor(desc);
>                     } else {
>
> --
> View this message in context:
> http://www.nabble.com/use-isPrimitive%28%29-instead-of-comparing-the-string-to-a-list-of-primitives-tp15267788s16868p15329675.html
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com
> .
>
>

Re: use isPrimitive() instead of comparing the string to a list of primitives

Posted by Stivo <sp...@gmx.net>.
I figured out how to make a patch so here goes.
I ran the maven test with it, and it ran fine.

Index: C:/Users/Stivo/workspacenew/mina
trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
===================================================================
--- C:/Users/Stivo/workspacenew/mina
trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java	(revision
619305)
+++ C:/Users/Stivo/workspacenew/mina
trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java	(working copy)
@@ -306,20 +306,6 @@
         return newCapacity;
     }
     
-    protected static final Set<String> primitiveTypeNames = new
HashSet<String>();
-    
-    static {
-        primitiveTypeNames.add("void");
-        primitiveTypeNames.add("boolean");
-        primitiveTypeNames.add("byte");
-        primitiveTypeNames.add("char");
-        primitiveTypeNames.add("short");
-        primitiveTypeNames.add("int");
-        primitiveTypeNames.add("long");
-        primitiveTypeNames.add("float");
-        primitiveTypeNames.add("double");
-    }
-
     /**
      * Creates a new instance.  This is an empty constructor.
      */
Index: C:/Users/Stivo/workspacenew/mina
trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
===================================================================
--- C:/Users/Stivo/workspacenew/mina
trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
(revision 619305)
+++ C:/Users/Stivo/workspacenew/mina
trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
(working copy)
@@ -1608,8 +1608,7 @@
                 @Override
                 protected void writeClassDescriptor(ObjectStreamClass desc)
                         throws IOException {
-                    String className = desc.getName();
-                    if (primitiveTypeNames.contains(className)) {
+                	if (desc.forClass().isPrimitive()) {
                         write(0);
                         super.writeClassDescriptor(desc);
                     } else {

-- 
View this message in context: http://www.nabble.com/use-isPrimitive%28%29-instead-of-comparing-the-string-to-a-list-of-primitives-tp15267788s16868p15329675.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.