From e4c0705ff5ac98e9dc62de0758f1edf67285325a Mon Sep 17 00:00:00 2001 From: RedMser Date: Sun, 23 Sep 2018 20:59:09 +0200 Subject: [PATCH 1/4] Removed redundant reflection calls to improve binary decoding speed. --- Codecs/Binary.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Codecs/Binary.cs b/Codecs/Binary.cs index 699c33d..63f15d4 100644 --- a/Codecs/Binary.cs +++ b/Codecs/Binary.cs @@ -59,7 +59,7 @@ static byte TypeToId(Type type, int version) return ++i; } - Type IdToType(byte id) + Tuple IdToType(byte id) { var type_list = SupportedAttributes[EncodingVersion]; bool array = false; @@ -82,7 +82,7 @@ Type IdToType(byte id) try { - return array ? type_list[id].MakeListType() : type_list[id]; + return new Tuple((array ? type_list[id].MakeListType() : type_list[id]), (array ? type_list[id] : null)); } catch (IndexOutOfRangeException) { @@ -371,14 +371,14 @@ public object DeferredDecodeAttribute(Datamodel dm, long offset) object DecodeAttribute(Datamodel dm) { - var type = IdToType(Reader.ReadByte()); + var types = IdToType(Reader.ReadByte()); - if (!Datamodel.IsDatamodelArrayType(type)) - return ReadValue(dm, type, EncodingVersion < 4); + if (types.Item2 == null) + return ReadValue(dm, types.Item1, EncodingVersion < 4); else { var count = Reader.ReadInt32(); - var inner_type = Datamodel.GetArrayInnerType(type); + var inner_type = types.Item2; var array = CodecUtilities.MakeList(inner_type, count); foreach (var x in Enumerable.Range(0, count)) @@ -390,15 +390,14 @@ object DecodeAttribute(Datamodel dm) void SkipAttribte() { - var type = IdToType(Reader.ReadByte()); + var types = IdToType(Reader.ReadByte()); int count = 1; - bool array = false; - if (Datamodel.IsDatamodelArrayType(type)) + Type type = types.Item1; + if (types.Item2 != null) { - array = true; count = Reader.ReadInt32(); - type = Datamodel.GetArrayInnerType(type); + type = types.Item2; } if (type == typeof(Element)) @@ -424,7 +423,7 @@ void SkipAttribte() } else if (type == typeof(string)) { - if (!StringDict.Dummy && !array && EncodingVersion >= 4) + if (!StringDict.Dummy && types.Item2 == null && EncodingVersion >= 4) length = StringDict.IndiceSize; else { From cbf523da3eb4058229d476891c036ed0f8c1a682 Mon Sep 17 00:00:00 2001 From: RedMser Date: Sun, 23 Sep 2018 21:00:36 +0200 Subject: [PATCH 2/4] Updated .gitignore for VS2015 --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index a7586c0..880b725 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ # User-specific files *.suo *.user +*.userosscache *.sln.docstates # Build results @@ -36,6 +37,9 @@ .builds *.dotCover +# Visual Studio 2015 cache/options directory +.vs/ + ## TODO: If you have NuGet Package Restore enabled, uncomment this #packages/ From 8f4b3081078c23935cd6b381cd4df8b4294264db Mon Sep 17 00:00:00 2001 From: RedMser Date: Sun, 23 Sep 2018 21:01:11 +0200 Subject: [PATCH 3/4] Fixed incorrect formatting string --- Codecs/KeyValues2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Codecs/KeyValues2.cs b/Codecs/KeyValues2.cs index 6647bec..b0caef6 100644 --- a/Codecs/KeyValues2.cs +++ b/Codecs/KeyValues2.cs @@ -283,7 +283,7 @@ void WriteAttribute(string name, Type type, object value, bool in_array) void WriteElement(Element element) { if (TypeNames.ContainsValue(element.ClassName)) - throw new CodecException(String.Format("Element {} uses reserved type name \"{1}\".", element.ID, element.ClassName)); + throw new CodecException(String.Format("Element {0} uses reserved type name \"{1}\".", element.ID, element.ClassName)); Writer.WriteTokens(element.ClassName); Writer.WriteLine("{"); Writer.Indent++; From 2636dde6032f59d43b96882dea3cc83fd8806b71 Mon Sep 17 00:00:00 2001 From: RedMser Date: Sun, 23 Sep 2018 21:02:07 +0200 Subject: [PATCH 4/4] Fixed spelling mistake on function name --- Codecs/Binary.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Codecs/Binary.cs b/Codecs/Binary.cs index 63f15d4..b85ffb4 100644 --- a/Codecs/Binary.cs +++ b/Codecs/Binary.cs @@ -350,7 +350,7 @@ public Datamodel Decode(int encoding_version, string format, int format_version, if (defer_mode == DeferredMode.Automatic) { CodecUtilities.AddDeferredAttribute(elem, name, Reader.BaseStream.Position); - SkipAttribte(); + SkipAttribute(); } else { @@ -388,7 +388,7 @@ object DecodeAttribute(Datamodel dm) } } - void SkipAttribte() + void SkipAttribute() { var types = IdToType(Reader.ReadByte());