THRIFT-998. java: Using valueOf for base types in getFieldValue
authorBryan Duxbury <bryanduxbury@apache.org>
Wed, 26 Jan 2011 18:29:33 +0000 (18:29 +0000)
committerBryan Duxbury <bryanduxbury@apache.org>
Wed, 26 Jan 2011 18:29:33 +0000 (18:29 +0000)
valueOf saves us on memory for 'small' primitive types and costs us nothing in other situations, so it's an all-around win.

Patch: Takashi Yonebayashi

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1063818 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_java_generator.cc

index 376db02..a7904dc 100644 (file)
@@ -1690,7 +1690,7 @@ void t_java_generator::generate_reflection_getters(ostringstream& out, t_type* t
   if (type->is_base_type() && !type->is_string()) {
     t_base_type* base_type = (t_base_type*)type;
 
-    indent(out) << "return new " << type_name(type, true, false) << "(" << (base_type->is_bool() ? "is" : "get") << cap_name << "());" << endl << endl;
+    indent(out) << "return " << type_name(type, true, false) << ".valueOf(" << (base_type->is_bool() ? "is" : "get") << cap_name << "());" << endl << endl;
   } else {
     indent(out) << "return get" << cap_name << "();" << endl << endl;
   }