C++: Make write{Struct,Field}Begin take "name" as a const char*.

Summary:
These methods previously took name as a const string&.  While that way
is more idiomatic, it requires a temporary string to be constructed
when we pass a string literal (which is always).  This was significantly
slowing down the serialization of field-heavy structures.  This change
will break ABI compatibility, but the serialization speed boost with
no external API changes is too important to pass up.

Reviewed By: mcslee, aditya

Test Plan: make check

TracCamp Project: Thrift

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665672 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cpp b/lib/cpp/src/protocol/TBinaryProtocol.cpp
index 2d98395..1c8cf55 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cpp
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cpp
@@ -75,7 +75,7 @@
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeStructBegin(const string& name) {
+uint32_t TBinaryProtocol::writeStructBegin(const char* name) {
   return 0;
 }
 
@@ -83,7 +83,7 @@
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeFieldBegin(const string& name,
+uint32_t TBinaryProtocol::writeFieldBegin(const char* name,
                                           const TType fieldType,
                                           const int16_t fieldId) {
   uint32_t wsize = 0;
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h
index dc47b3a..a6a8983 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.h
+++ b/lib/cpp/src/protocol/TBinaryProtocol.h
@@ -79,11 +79,11 @@
   virtual uint32_t writeMessageEnd();
 
 
-  uint32_t writeStructBegin(const std::string& name);
+  uint32_t writeStructBegin(const char* name);
 
   uint32_t writeStructEnd();
 
-  uint32_t writeFieldBegin(const std::string& name,
+  uint32_t writeFieldBegin(const char* name,
                            const TType fieldType,
                            const int16_t fieldId);
 
diff --git a/lib/cpp/src/protocol/TDebugProtocol.cpp b/lib/cpp/src/protocol/TDebugProtocol.cpp
index 4cc3df8..92e9d36 100644
--- a/lib/cpp/src/protocol/TDebugProtocol.cpp
+++ b/lib/cpp/src/protocol/TDebugProtocol.cpp
@@ -152,10 +152,10 @@
   return writeIndented(")\n");
 }
 
-uint32_t TDebugProtocol::writeStructBegin(const string& name) {
+uint32_t TDebugProtocol::writeStructBegin(const char* name) {
   uint32_t size = 0;
   size += startItem();
-  size += writePlain(name + " {\n");
+  size += writePlain(string(name) + " {\n");
   indentUp();
   write_state_.push_back(STRUCT);
   return size;
@@ -170,7 +170,7 @@
   return size;
 }
 
-uint32_t TDebugProtocol::writeFieldBegin(const string& name,
+uint32_t TDebugProtocol::writeFieldBegin(const char* name,
                                          const TType fieldType,
                                          const int16_t fieldId) {
   // sprintf(id_str, "%02d", fieldId);
diff --git a/lib/cpp/src/protocol/TDebugProtocol.h b/lib/cpp/src/protocol/TDebugProtocol.h
index 310c2b2..bac2098 100644
--- a/lib/cpp/src/protocol/TDebugProtocol.h
+++ b/lib/cpp/src/protocol/TDebugProtocol.h
@@ -75,11 +75,11 @@
   virtual uint32_t writeMessageEnd();
 
 
-  uint32_t writeStructBegin(const std::string& name);
+  uint32_t writeStructBegin(const char* name);
 
   uint32_t writeStructEnd();
 
-  uint32_t writeFieldBegin(const std::string& name,
+  uint32_t writeFieldBegin(const char* name,
                            const TType fieldType,
                            const int16_t fieldId);
 
diff --git a/lib/cpp/src/protocol/TDenseProtocol.cpp b/lib/cpp/src/protocol/TDenseProtocol.cpp
index dbb2d4a..d1602a0 100644
--- a/lib/cpp/src/protocol/TDenseProtocol.cpp
+++ b/lib/cpp/src/protocol/TDenseProtocol.cpp
@@ -267,7 +267,7 @@
   return 0;
 }
 
-uint32_t TDenseProtocol::writeStructBegin(const string& name) {
+uint32_t TDenseProtocol::writeStructBegin(const char* name) {
   uint32_t xfer = 0;
 
   // The TypeSpec stack should be empty if this is the top-level read/write.
@@ -298,7 +298,7 @@
   return 0;
 }
 
-uint32_t TDenseProtocol::writeFieldBegin(const string& name,
+uint32_t TDenseProtocol::writeFieldBegin(const char* name,
                                          const TType fieldType,
                                          const int16_t fieldId) {
   uint32_t xfer = 0;
diff --git a/lib/cpp/src/protocol/TDenseProtocol.h b/lib/cpp/src/protocol/TDenseProtocol.h
index 713b57a..5dd5a8c 100644
--- a/lib/cpp/src/protocol/TDenseProtocol.h
+++ b/lib/cpp/src/protocol/TDenseProtocol.h
@@ -84,11 +84,11 @@
   virtual uint32_t writeMessageEnd();
 
 
-  virtual uint32_t writeStructBegin(const std::string& name);
+  virtual uint32_t writeStructBegin(const char* name);
 
   virtual uint32_t writeStructEnd();
 
-  virtual uint32_t writeFieldBegin(const std::string& name,
+  virtual uint32_t writeFieldBegin(const char* name,
                                    const TType fieldType,
                                    const int16_t fieldId);
 
diff --git a/lib/cpp/src/protocol/TJSONProtocol.cpp b/lib/cpp/src/protocol/TJSONProtocol.cpp
index b2ffeac..a7564d1 100644
--- a/lib/cpp/src/protocol/TJSONProtocol.cpp
+++ b/lib/cpp/src/protocol/TJSONProtocol.cpp
@@ -546,7 +546,7 @@
   return writeJSONArrayEnd();
 }
 
-uint32_t TJSONProtocol::writeStructBegin(const std::string& name) {
+uint32_t TJSONProtocol::writeStructBegin(const char* name) {
   return writeJSONObjectStart();
 }
 
@@ -554,7 +554,7 @@
   return writeJSONObjectEnd();
 }
 
-uint32_t TJSONProtocol::writeFieldBegin(const std::string& name,
+uint32_t TJSONProtocol::writeFieldBegin(const char* name,
                                         const TType fieldType,
                                         const int16_t fieldId) {
   uint32_t result = writeJSONInteger(fieldId);
diff --git a/lib/cpp/src/protocol/TJSONProtocol.h b/lib/cpp/src/protocol/TJSONProtocol.h
index ddf48c7..efb8e63 100644
--- a/lib/cpp/src/protocol/TJSONProtocol.h
+++ b/lib/cpp/src/protocol/TJSONProtocol.h
@@ -150,11 +150,11 @@
 
   uint32_t writeMessageEnd();
 
-  uint32_t writeStructBegin(const std::string& name);
+  uint32_t writeStructBegin(const char* name);
 
   uint32_t writeStructEnd();
 
-  uint32_t writeFieldBegin(const std::string& name,
+  uint32_t writeFieldBegin(const char* name,
                            const TType fieldType,
                            const int16_t fieldId);
 
diff --git a/lib/cpp/src/protocol/TOneWayProtocol.h b/lib/cpp/src/protocol/TOneWayProtocol.h
index 3c31d1e..dda113f 100644
--- a/lib/cpp/src/protocol/TOneWayProtocol.h
+++ b/lib/cpp/src/protocol/TOneWayProtocol.h
@@ -183,7 +183,7 @@
   }
 
 
-  uint32_t writeStructBegin(const std::string& name) {
+  uint32_t writeStructBegin(const char* name) {
     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
         subclass_ + " does not support writing (yet).");
   }
@@ -193,7 +193,7 @@
         subclass_ + " does not support writing (yet).");
   }
 
-  uint32_t writeFieldBegin(const std::string& name,
+  uint32_t writeFieldBegin(const char* name,
                            const TType fieldType,
                            const int16_t fieldId) {
     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h
index aecc4e7..1e9ce99 100644
--- a/lib/cpp/src/protocol/TProtocol.h
+++ b/lib/cpp/src/protocol/TProtocol.h
@@ -117,11 +117,11 @@
   virtual uint32_t writeMessageEnd() = 0;
 
 
-  virtual uint32_t writeStructBegin(const std::string& name) = 0;
+  virtual uint32_t writeStructBegin(const char* name) = 0;
 
   virtual uint32_t writeStructEnd() = 0;
 
-  virtual uint32_t writeFieldBegin(const std::string& name,
+  virtual uint32_t writeFieldBegin(const char* name,
                                    const TType fieldType,
                                    const int16_t fieldId) = 0;
 
diff --git a/lib/cpp/src/protocol/TProtocolTap.h b/lib/cpp/src/protocol/TProtocolTap.h
index 1259598..162f783 100644
--- a/lib/cpp/src/protocol/TProtocolTap.h
+++ b/lib/cpp/src/protocol/TProtocolTap.h
@@ -45,7 +45,7 @@
 
   virtual uint32_t readStructBegin(std::string& name) {
     uint32_t rv = source_->readStructBegin(name);
-    sink_->writeStructBegin(name);
+    sink_->writeStructBegin(name.c_str());
     return rv;
   }
 
@@ -62,7 +62,7 @@
     if (fieldType == T_STOP) {
       sink_->writeFieldStop();
     } else {
-      sink_->writeFieldBegin(name, fieldType, fieldId);
+      sink_->writeFieldBegin(name.c_str(), fieldType, fieldId);
     }
     return rv;
   }