From: eletuchy Date: Wed, 13 Feb 2008 22:44:24 +0000 (+0000) Subject: [thrift] making generated php struct readers more compact X-Git-Tag: 0.2.0~994 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=bbf8062e4f37bde9e698e080b9f2017dd93bbfc6;p=common%2Fthrift.git [thrift] making generated php struct readers more compact Summary: introducing a $bin_accel variable in struct reader scope that can be reference by the deserializers of each field Reviewed By: dreiss, mcslee Test Plan: regenerated a thrift service, compared before and after calls Revert Plan: sure git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665478 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index 1f4ed1fc..9ed473e1 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -498,6 +498,10 @@ void t_php_generator::generate_php_struct_reader(ofstream& out, return; } + out << + indent() << "$bin_accel = ($input instanceof TProtocol::$TBINARYPROTOCOLACCELERATED)" + << " && function_exists('thrift_protocol_binary_deserialize');" << endl; + out << indent() << "$xfer = 0;" << endl << indent() << "$fname = null;" << endl << @@ -1337,7 +1341,7 @@ void t_php_generator::generate_deserialize_field(ofstream &out, generate_deserialize_container(out, type, name); } else if (type->is_base_type() || type->is_enum()) { - out << indent() << "if (($input instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_binary_deserialize')) {" << endl; + out << indent() << "if ($bin_accel) {" << endl; indent_up(); string ttype_name; if (type->is_enum()) { @@ -1471,8 +1475,8 @@ void t_php_generator::generate_deserialize_field(ofstream &out, } out << endl; } - out << indent() << "}" << endl; indent_down(); + out << indent() << "}" << endl; } else { printf("DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n", tfield->get_name().c_str(), type->get_name().c_str()); @@ -1497,7 +1501,7 @@ void t_php_generator::generate_deserialize_struct(ofstream &out, void t_php_generator::generate_deserialize_container(ofstream &out, t_type* ttype, string prefix) { - out << indent() << "if (($input instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_binary_deserialize'))" << endl; + out << indent() << "if ($bin_accel)" << endl; scope_up(out); string ttype_name;