From 89d52079834a20411d2b842d2e71a4e3390911a9 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Wed, 14 Nov 2007 00:24:14 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_php_generator.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index ed5a0178..c16cfa4b 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -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& 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())) { -- 2.17.1