Change Thrift to lazily instantiate $_TSPEC objects on first object instantiation

Summary: Apparently adding the static array costs overhead since it must get preinitialized or something? It's unclear exactly what's going on here, but let's test to see if explicit lazy instantiation helps here.

Reviewed By: dreiss

Test Plan: See if this speeds up falcon loading


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665334 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Slee 2007-11-14 00:24:14 +00:00
parent 465ccc0924
commit 89d5207983

View File

@ -333,7 +333,10 @@ void t_php_generator::generate_php_type_spec(ofstream& out,
*/
void t_php_generator::generate_php_struct_spec(ofstream& out,
t_struct* tstruct) {
indent(out) << "static $_TSPEC = array(" << endl;
indent(out) << "if (!isset(self::$_TSPEC)) {" << endl;
indent_up();
indent(out) << "self::$_TSPEC = array(" << endl;
indent_up();
const vector<t_field*>& members = tstruct->get_members();
@ -351,6 +354,8 @@ void t_php_generator::generate_php_struct_spec(ofstream& out,
indent_down();
indent(out) << " );" << endl;
indent_down();
indent(out) << "}" << endl;
}
@ -378,7 +383,7 @@ void t_php_generator::generate_php_struct_definition(ofstream& out,
" {" << endl;
indent_up();
generate_php_struct_spec(out, tstruct);
indent(out) << "static $_TSPEC;" << endl << endl;
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
string dval = "null";
@ -398,6 +403,8 @@ void t_php_generator::generate_php_struct_definition(ofstream& out,
indent() << "public function __construct($vals=null) {" << endl;
indent_up();
generate_php_struct_spec(out, tstruct);
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
t_type* t = get_true_type((*m_iter)->get_type());
if ((*m_iter)->get_value() != NULL && (t->is_struct() || t->is_xception())) {