[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CompiledExpression.evaluate implementation
From: |
Mark Taylor |
Subject: |
CompiledExpression.evaluate implementation |
Date: |
Tue, 17 Nov 2020 10:48:08 +0000 (GMT) |
User-agent: |
Alpine 2.21 (DEB 202 2017-01-01) |
Konstantin,
while I'm talking to you, I have another suggestion.
In gnu.jel.CompiledExpression.evaluate you have this code:
switch (type) {
case 0: res=new Boolean(evaluate_boolean(dl)); break;
case 1: res=new Byte(evaluate_byte(dl)); break;
case 2: res=new Character(evaluate_char(dl)); break;
case 3: res=new Short(evaluate_short(dl)); break;
case 4: res=new Integer(evaluate_int(dl)); break;
case 5: res=new Long(evaluate_long(dl)); break;
case 6: res=new Float(evaluate_float(dl)); break;
case 7: res=new Double(evaluate_double(dl)); break;
case 9: evaluate_void(dl); break;
...
What do you think about writing instead:
case 0: res=Boolean.valueOf(evaluate_boolean(dl)); break;
case 1: res=Byte.valueOf(evaluate_byte(dl)); break;
since those methods avoid object creation by using pre-constructed
Boolean/Byte object instances (see the advice in the javadocs
for those static methods). The case is less clear for the other
types; although the javadocs suggest that valueOf is "likely to
yield significantly better space and time performance by caching
frequently requested values" for all those wrapper class valueOf
methods, I have sometimes found in tests that they are slower
than using the constructors, presumably because of lookup overheads.
Thanks for considering,
Mark
--
Mark Taylor Astronomical Programmer Physics, Bristol University, UK
m.b.taylor@bris.ac.uk +44-117-9288776 http://www.star.bris.ac.uk/~mbt/
- CompiledExpression.evaluate implementation,
Mark Taylor <=