avoid stupid string allocation all the time.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 07 May 2008 15:01:45 -0700
changeset 3051 399d3858d190
parent 3050 9cc612c6cd32
child 3052 f64799121881
avoid stupid string allocation all the time.
utils/bench-packets.cc
--- a/utils/bench-packets.cc	Wed May 07 13:47:19 2008 -0700
+++ b/utils/bench-packets.cc	Wed May 07 15:01:45 2008 -0700
@@ -22,6 +22,7 @@
 #include "ns3/packet-metadata.h"
 #include <iostream>
 #include <sstream>
+#include <string>
 
 using namespace ns3;
 
@@ -39,6 +40,7 @@
   virtual void Serialize (Buffer::Iterator start) const;
   virtual uint32_t Deserialize (Buffer::Iterator start);
 private:
+  static std::string GetTypeName (void);
   bool m_ok;
 };
 
@@ -55,12 +57,19 @@
 }
 
 template <int N>
+std::string 
+BenchHeader<N>::GetTypeName (void)
+{
+  std::ostringstream oss;
+  oss << "ns3::BenchHeader<" << N << ">";
+  return oss.str ();
+}
+
+template <int N>
 TypeId 
 BenchHeader<N>::GetTypeId (void)
 {
-  std::ostringstream oss;
-  oss << "ns3::BenchHeader<"<<N<<">";
-  static TypeId tid = TypeId (oss.str ().c_str ())
+  static TypeId tid = TypeId (GetTypeName ().c_str ())
     .SetParent<Header> ()
     ;
   return tid;