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, [EMAIL PROTECTED]
Re: use isPrimitive() instead of comparing the string to a list of primitives
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 primitiveTypeNames = new HashSet(); - -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
Hi Stivo, Thanks for the patch ! I will have a look at it. Maarten On Feb 7, 2008 9:56 AM, Stivo <[EMAIL PROTECTED]> 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 primitiveTypeNames = new > HashSet(); > - > -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
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 <[EMAIL PROTECTED]> wrote: > Hi Stivo, > > Thanks for the patch ! > I will have a look at it. > > Maarten > > > On Feb 7, 2008 9:56 AM, Stivo <[EMAIL PROTECTED]> 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 primitiveTypeNames = new > > HashSet(); > > - > > -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
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.
[jira] Created: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
use isPrimitive() instead of comparing the string to a list of primitives - Key: DIRMINA-529 URL: https://issues.apache.org/jira/browse/DIRMINA-529 Project: MINA Issue Type: Improvement Components: Core Affects Versions: 2.0.0-M1 Reporter: Stefan Ackermann Priority: Minor Attachments: mina-patch.txt Never done this before, will try to attach the patch -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Stefan Ackermann updated DIRMINA-529: - Attachment: mina-patch.txt > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Priority: Minor > Attachments: mina-patch.txt > > > Never done this before, will try to attach the patch -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Stefan Ackermann updated DIRMINA-529: - Description: isPrimitive is a native function and should be used to determine whether a class is primitive instead of comparing to a list of known primitive class names (was: Never done this before, will try to attach the patch) > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Priority: Minor > Attachments: mina-patch.txt > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Commented: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12567439#action_12567439 ] Johannes Ulfkjær Jensen commented on DIRMINA-529: - Hi, I am not sure I am allowed to paste code into this comment field so I will try to describe another approach in words. Looking at the patch, it seems you can get the actual Class object for free, so why not just identify-compare that to the Class objects for the primitive types? You avoid the overhead of a native call, and being pure java, I think (pure speculation) that the JIT would have an easier time compiling it. This is obviously just an extreme mini optimization (compared to the patch) but I thought I would chime in regardless :) > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Priority: Minor > Attachments: mina-patch.txt > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Mike Heath updated DIRMINA-529: --- Fix Version/s: 2.0.0-M2 > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Resolved: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Trustin Lee resolved DIRMINA-529. - Resolution: Fixed Assignee: Trustin Lee Thanks for the patch. It has been applied to the trunk. > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Commented: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12577680#action_12577680 ] Trustin Lee commented on DIRMINA-529: - I'm not sure that isPrimitive() is slower than if - else if - ... block. Any benchmark report is appreciated. > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Edouard De Oliveira updated DIRMINA-529: Attachment: Primitive.java Here's a simple benchmark between the two methods. Ran under jdk1.6.0_3, output is : Elapsed method 1 = 531 Elapsed method 2 = 1297 > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt, Primitive.java > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Johannes Ulfkjær Jensen updated DIRMINA-529: Attachment: Primitive.java > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt, Primitive.java, Primitive.java > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Commented: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12577953#action_12577953 ] Johannes Ulfkjær Jensen commented on DIRMINA-529: - I find it quite surprising that the existing method is actually better! and just to serve my own ego I extended the benchmark with my method. The results are: Elapsed method 1 = 178816721 Elapsed method 2 = 571406491 Elapsed method 3 = 136158715 java.vm.version=1.6.0_02-b05 java.vm.name=Java HotSpot(TM) 64-Bit Server VM os.name=Windows Vista true And given that it is a mini benchmark I tried to move them around a little and got this also: Elapsed method 3 = 76254315 Elapsed method 1 = 190396475 Elapsed method 2 = 604831410 java.vm.version=1.6.0_02-b05 java.vm.name=Java HotSpot(TM) 64-Bit Server VM os.name=Windows Vista true Not sure why this is the case. Any ideas? Will try to attach my the extended and slightly altered benchmark. > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt, Primitive.java, Primitive.java > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Updated: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Trustin Lee updated DIRMINA-529: Attachment: Primitive.java I modified the Primitive.java you provided me, and got the following result: Elapsed method 1 = 35200 Elapsed method 2 = 6 Elapsed method 3 = 4168 Elapsed method 1 = 35895 Elapsed method 2 = 1 Elapsed method 3 = 4128 Elapsed method 1 = 29329 Elapsed method 2 = 0 Elapsed method 3 = 3730 ... I also changed the order of each tests (i.e. 3->1->2), but didn't find any difference. So far, isPrimitive() seems to ourperform all alternatives. I'm on Linux with SUN JDK 1.6.0_05 Server VM. > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt, Primitive.java, Primitive.java, > Primitive.java > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Closed: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Julien Vermillard closed DIRMINA-529. - > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt, Primitive.java, Primitive.java, > Primitive.java > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (DIRMINA-529) use isPrimitive() instead of comparing the string to a list of primitives
[ https://issues.apache.org/jira/browse/DIRMINA-529?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12577953#action_12577953 ] spand edited comment on DIRMINA-529 at 3/12/08 10:52 AM: --- I find it quite surprising that the existing method is actually better! and just to serve my own ego I extended the benchmark with my method. The results are: Elapsed method 1 = 178816721 Elapsed method 2 = 571406491 Elapsed method 3 = 136158715 java.vm.version=1.6.0_02-b05 java.vm.name=Java HotSpot(TM) 64-Bit Server VM os.name=Windows Vista true And given that it is a mini benchmark I tried to move them around a little and got this also: Elapsed method 3 = 76254315 Elapsed method 1 = 190396475 Elapsed method 2 = 604831410 java.vm.version=1.6.0_02-b05 java.vm.name=Java HotSpot(TM) 64-Bit Server VM os.name=Windows Vista true Not sure why this is the case. Any ideas? Will try to attach the extended and slightly altered benchmark. was (Author: spand): I find it quite surprising that the existing method is actually better! and just to serve my own ego I extended the benchmark with my method. The results are: Elapsed method 1 = 178816721 Elapsed method 2 = 571406491 Elapsed method 3 = 136158715 java.vm.version=1.6.0_02-b05 java.vm.name=Java HotSpot(TM) 64-Bit Server VM os.name=Windows Vista true And given that it is a mini benchmark I tried to move them around a little and got this also: Elapsed method 3 = 76254315 Elapsed method 1 = 190396475 Elapsed method 2 = 604831410 java.vm.version=1.6.0_02-b05 java.vm.name=Java HotSpot(TM) 64-Bit Server VM os.name=Windows Vista true Not sure why this is the case. Any ideas? Will try to attach my the extended and slightly altered benchmark. > use isPrimitive() instead of comparing the string to a list of primitives > - > > Key: DIRMINA-529 > URL: https://issues.apache.org/jira/browse/DIRMINA-529 > Project: MINA > Issue Type: Improvement > Components: Core >Affects Versions: 2.0.0-M1 >Reporter: Stefan Ackermann >Assignee: Trustin Lee >Priority: Minor > Fix For: 2.0.0-M2 > > Attachments: mina-patch.txt, Primitive.java, Primitive.java > > > isPrimitive is a native function and should be used to determine whether a > class is primitive instead of comparing to a list of known primitive class > names -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.