[jbosscache-dev] reworking CacheMarshaller200.marshallObject() to a switch statement?

Manik Surtani manik at jboss.org
Sat Feb 3 05:14:43 EST 2007


True, instanceof is probably a bad idea here because subclasses may  
need to be unmarshalled differently.

How would performance of a map lookup versus an if statement compare?

--
Manik Surtani

Lead, JBoss Cache
JBoss, a division of Red Hat

Email: manik at jboss.org
Telephone: +44 7786 702 706
MSN: manik at surtani.org
Yahoo/AIM/Skype: maniksurtani



On 2 Feb 2007, at 15:54, Galder Zamarreno wrote:

> Looking at CacheMarshaller200.marshallObject, we seem to have quite  
> a big if chain. For BETA2, I was thinking that we could create a  
> static Map<Class, int> containing class names and magic numbers,  
> similar to the work we did for MethodDeclarations.
>
> public static final Map COLLECTIONS = new HashMap();
>
> static
> {
>   COLLECTIONS.put(ArrayList.class, MAGICNUMBER_ARRAY_LIST);
> }
>
> ...
>
> int i = COLLECTIONS.get(o.getClass());
> switch(i)
> {
>   Case MAGICNUMBER_ARRAY_LIST: ...
> }
>
> Also, the instanceof if statements could be translated into this,  
> specially bearing in mind that when we unmarshall, we create new  
> instances of the class we compared for in the instanceof statement,  
> so we would be back to the problem we had with the customer  
> collections.
>
> Galder Zamarreño
> Sr. Software Maintenance Engineer
> JBoss, a division of Red Hat
>
>
>
> _______________________________________________
> jbosscache-dev mailing list
> jbosscache-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jbosscache-dev





More information about the jbosscache-dev mailing list