From: David Reiss Date: Wed, 6 Feb 2008 22:09:58 +0000 (+0000) Subject: Thrift: Miscellaneous optimizations for C#. X-Git-Tag: 0.2.0~1008 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=46dc62950d24cf785415de040255b3b0c67ecb3a;p=common%2Fthrift.git Thrift: Miscellaneous optimizations for C#. Reviewed By: mcslee Test Plan: Built it after a future revision. Revert Plan: ok Other Notes: Submitted by Ben Maurer. Actually reviewed by Todd Berman. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665464 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc index 48df1b09..fceec849 100644 --- a/compiler/cpp/src/generate/t_csharp_generator.cc +++ b/compiler/cpp/src/generate/t_csharp_generator.cc @@ -321,12 +321,12 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream &out, t_stru if (members.size() > 0) { out << endl << - indent() << "public Isset __isset = new Isset();" << endl << - indent() << "public sealed class Isset {" << endl; + indent() << "public Isset __isset;" << endl << + indent() << "public struct Isset {" << endl; indent_up(); for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) { indent(out) << - "public bool " << (*m_iter)->get_name() << " = false;" << endl; + "public bool " << (*m_iter)->get_name() << ";" << endl; } indent_down(); @@ -593,7 +593,7 @@ void t_csharp_generator::generate_csharp_struct_tostring(ofstream& out, t_struct t_type* ttype = (*f_iter)->get_type(); if (ttype->is_xception() || ttype->is_struct()) { indent(out) << - "sb.Append(this." << (*f_iter)->get_name() << ".ToString());" << endl; + "sb.Append(this." << (*f_iter)->get_name() << "== null ? \"\" : "<< "this." << (*f_iter)->get_name() << ".ToString());" << endl; } else { indent(out) << "sb.Append(this." << (*f_iter)->get_name() << ");" << endl; @@ -1384,7 +1384,7 @@ string t_csharp_generator::type_name(t_type* ttype, bool in_container, bool in_i } if (ttype->is_base_type()) { - return base_type_name(((t_base_type*)ttype)->get_base(), in_container); + return base_type_name((t_base_type*)ttype, in_container); } else if (ttype->is_map()) { t_map *tmap = (t_map*) ttype; return "Dictionary<" + type_name(tmap->get_key_type(), true) + diff --git a/lib/csharp/src/Protocol/TField.cs b/lib/csharp/src/Protocol/TField.cs index f18381ff..93295309 100644 --- a/lib/csharp/src/Protocol/TField.cs +++ b/lib/csharp/src/Protocol/TField.cs @@ -16,12 +16,8 @@ using System.Text; namespace Thrift.Protocol { - public class TField + public struct TField { - public TField() - { - } - public TField(string name, TType type, short id) { Name = name; diff --git a/lib/csharp/src/Protocol/TList.cs b/lib/csharp/src/Protocol/TList.cs index ff6aa533..72056cb8 100644 --- a/lib/csharp/src/Protocol/TList.cs +++ b/lib/csharp/src/Protocol/TList.cs @@ -16,12 +16,8 @@ using System.Text; namespace Thrift.Protocol { - public class TList + public struct TList { - public TList() - { - } - public TList(TType elementType, int count) { ElementType = elementType; diff --git a/lib/csharp/src/Protocol/TMap.cs b/lib/csharp/src/Protocol/TMap.cs index 495bf7cc..586aa4f6 100644 --- a/lib/csharp/src/Protocol/TMap.cs +++ b/lib/csharp/src/Protocol/TMap.cs @@ -16,12 +16,8 @@ using System.Text; namespace Thrift.Protocol { - public class TMap + public struct TMap { - public TMap() - { - } - public TMap(TType keyType, TType valueType, int count) { KeyType = keyType; diff --git a/lib/csharp/src/Protocol/TMessage.cs b/lib/csharp/src/Protocol/TMessage.cs index 60df6607..a9522ff0 100644 --- a/lib/csharp/src/Protocol/TMessage.cs +++ b/lib/csharp/src/Protocol/TMessage.cs @@ -16,12 +16,8 @@ using System.Text; namespace Thrift.Protocol { - public class TMessage + public struct TMessage { - public TMessage() - { - } - public TMessage(string name, TMessageType type, int seqid) { Name = name; diff --git a/lib/csharp/src/Protocol/TProtocolException.cs b/lib/csharp/src/Protocol/TProtocolException.cs index 0941a81e..db38d88c 100644 --- a/lib/csharp/src/Protocol/TProtocolException.cs +++ b/lib/csharp/src/Protocol/TProtocolException.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; namespace Thrift.Protocol diff --git a/lib/csharp/src/Protocol/TSet.cs b/lib/csharp/src/Protocol/TSet.cs index c4c6fc33..1f172e47 100644 --- a/lib/csharp/src/Protocol/TSet.cs +++ b/lib/csharp/src/Protocol/TSet.cs @@ -16,12 +16,8 @@ using System.Text; namespace Thrift.Protocol { - public class TSet + public struct TSet { - public TSet() - { - } - public TSet(TType elementType, int count) { ElementType = elementType; diff --git a/lib/csharp/src/Protocol/TStruct.cs b/lib/csharp/src/Protocol/TStruct.cs index 88f12df6..000ebf11 100644 --- a/lib/csharp/src/Protocol/TStruct.cs +++ b/lib/csharp/src/Protocol/TStruct.cs @@ -15,12 +15,8 @@ using System.Text; namespace Thrift.Protocol { - public class TStruct + public struct TStruct { - public TStruct() - { - } - public TStruct(string name) { Name = name;