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
diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc
index ed5a017..c16cfa4 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_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 @@
 
   indent_down();
   indent(out) << "  );" << endl;
+  indent_down();
+  indent(out) << "}" << endl;
 }
 
 
@@ -378,7 +383,7 @@
     " {" << 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 @@
       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())) {