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 48df1b0..fceec84 100644
--- a/compiler/cpp/src/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/generate/t_csharp_generator.cc
@@ -321,12 +321,12 @@
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 @@
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 ? \"<null>\" : "<< "this." << (*f_iter)->get_name() << ".ToString());" << endl;
} else {
indent(out) <<
"sb.Append(this." << (*f_iter)->get_name() << ");" << endl;
@@ -1384,7 +1384,7 @@
}
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 f18381f..9329530 100644
--- a/lib/csharp/src/Protocol/TField.cs
+++ b/lib/csharp/src/Protocol/TField.cs
@@ -16,12 +16,8 @@
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 ff6aa53..72056cb 100644
--- a/lib/csharp/src/Protocol/TList.cs
+++ b/lib/csharp/src/Protocol/TList.cs
@@ -16,12 +16,8 @@
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 495bf7c..586aa4f 100644
--- a/lib/csharp/src/Protocol/TMap.cs
+++ b/lib/csharp/src/Protocol/TMap.cs
@@ -16,12 +16,8 @@
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 60df660..a9522ff 100644
--- a/lib/csharp/src/Protocol/TMessage.cs
+++ b/lib/csharp/src/Protocol/TMessage.cs
@@ -16,12 +16,8 @@
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 0941a81..db38d88 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 c4c6fc3..1f172e4 100644
--- a/lib/csharp/src/Protocol/TSet.cs
+++ b/lib/csharp/src/Protocol/TSet.cs
@@ -16,12 +16,8 @@
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 88f12df..000ebf1 100644
--- a/lib/csharp/src/Protocol/TStruct.cs
+++ b/lib/csharp/src/Protocol/TStruct.cs
@@ -15,12 +15,8 @@
namespace Thrift.Protocol
{
- public class TStruct
+ public struct TStruct
{
- public TStruct()
- {
- }
-
public TStruct(string name)
{
Name = name;