You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/11/02 17:37:10 UTC
[27/33] ignite git commit: wip Writer
wip Writer
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/46d3e046
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/46d3e046
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/46d3e046
Branch: refs/heads/ignite-1753-1282
Commit: 46d3e0464ee57385e1428aee7786f1f939e05481
Parents: 7f7111d
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Mon Nov 2 15:55:45 2015 +0300
Committer: Pavel Tupitsyn <pt...@gridgain.com>
Committed: Mon Nov 2 15:55:45 2015 +0300
----------------------------------------------------------------------
.../Impl/Portable/PortableObjectSchemaHolder.cs | 16 ++++++++++++--
.../Impl/Portable/PortableUtils.cs | 12 +++++------
.../Impl/Portable/PortableWriterImpl.cs | 22 ++++++++------------
3 files changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/46d3e046/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
index 0b0cd98..b66bdcc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs
@@ -62,16 +62,28 @@ namespace Apache.Ignite.Core.Impl.Portable
/// Writes collected schema to the stream and pops it.
/// </summary>
/// <param name="stream">The stream.</param>
- public void WriteAndPop(IPortableStream stream)
+ /// <param name="schemaId">The schema identifier.</param>
+ /// <returns>True if current schema was non empty; false otherwise.</returns>
+ public bool WriteAndPop(IPortableStream stream, out int schemaId)
{
var count = _offsets.Pop();
if (count > 0)
{
- PortableObjectSchemaField.WriteArray(_fields, stream, _idx - count, count);
+ var startIdx = _idx - count;
+
+ PortableObjectSchemaField.WriteArray(_fields, stream, startIdx, count);
+
+ schemaId = PortableUtils.GetSchemaId(_fields, startIdx, count);
_idx -= count;
+
+ return true;
}
+
+ schemaId = PortableUtils.GetSchemaId(null, 0, 0);
+
+ return false;
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/46d3e046/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
index a0657b2..46c5707 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableUtils.cs
@@ -1771,20 +1771,20 @@ namespace Apache.Ignite.Core.Impl.Portable
/// Gets the schema id as a Fnv1 hash.
/// </summary>
/// <param name="schema">The schema.</param>
+ /// <param name="start">Start index.</param>
+ /// <param name="count">Count.</param>
/// <returns>
/// Schema id.
/// </returns>
- public static int GetSchemaId(ResizeableArray<PortableObjectSchemaField> schema)
+ public static int GetSchemaId(PortableObjectSchemaField[] schema, int start, int count)
{
var hash = Fnv1Hash.Basis;
- if (schema == null || schema.Count == 0)
+ if (schema == null || schema.Length == 0)
return hash;
- var arr = schema.Array;
-
- for (int i = 0; i < schema.Count; i++)
- hash = Fnv1Hash.Update(hash, arr[i].Id);
+ for (int i = start; i < count; i++)
+ hash = Fnv1Hash.Update(hash, schema[i].Id);
return hash;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/46d3e046/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
index e17449d..b24b40d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableWriterImpl.cs
@@ -21,7 +21,7 @@ namespace Apache.Ignite.Core.Impl.Portable
using System.Collections;
using System.Collections.Generic;
using System.IO;
- using Apache.Ignite.Core.Impl.Common;
+ using System.Threading;
using Apache.Ignite.Core.Impl.Portable.IO;
using Apache.Ignite.Core.Impl.Portable.Metadata;
using Apache.Ignite.Core.Impl.Portable.Structure;
@@ -71,7 +71,8 @@ namespace Apache.Ignite.Core.Impl.Portable
private PortableStructureTracker _curStruct;
/** Current schema. */
- private ResizeableArray<PortableObjectSchemaField> _curSchema;
+ private ThreadLocal<PortableObjectSchemaHolder> _schema =
+ new ThreadLocal<PortableObjectSchemaHolder>(() => new PortableObjectSchemaHolder());
/// <summary>
@@ -1074,7 +1075,6 @@ namespace Apache.Ignite.Core.Impl.Portable
var oldPos = _curPos;
var oldStruct = _curStruct;
- var oldSchema = _curSchema;
// Push new frame.
_curTypeId = desc.TypeId;
@@ -1084,17 +1084,16 @@ namespace Apache.Ignite.Core.Impl.Portable
_curPos = pos;
_curStruct = new PortableStructureTracker(desc, desc.WriterTypeStructure);
- _curSchema = null;
+ _schema.Value.PushSchema();
// Write object fields.
desc.Serializer.WritePortable(obj, this);
// Write schema
- var hasSchema = _curSchema != null;
- var schemaOffset = hasSchema ? _stream.Position - pos : PortableObjectHeader.Size;
+ int schemaId;
+ var hasSchema = _schema.Value.WriteAndPop(_stream, out schemaId);
- if (hasSchema)
- PortableObjectSchemaField.WriteArray(_curSchema.Array, _stream, _curSchema.Count);
+ var schemaOffset = hasSchema ? _stream.Position - pos : PortableObjectHeader.Size;
// Calculate and write header.
if (hasSchema && _curRawPos > 0)
@@ -1103,7 +1102,7 @@ namespace Apache.Ignite.Core.Impl.Portable
var len = _stream.Position - pos;
var header = new PortableObjectHeader(desc.UserType, desc.TypeId, obj.GetHashCode(), len,
- PU.GetSchemaId(_curSchema), schemaOffset, !hasSchema);
+ schemaId, schemaOffset, !hasSchema);
PortableObjectHeader.Write(header, _stream, pos);
@@ -1120,7 +1119,6 @@ namespace Apache.Ignite.Core.Impl.Portable
_curPos = oldPos;
_curStruct = oldStruct;
- _curSchema = oldSchema;
}
else
{
@@ -1372,9 +1370,7 @@ namespace Apache.Ignite.Core.Impl.Portable
var fieldId = _curStruct.GetFieldId(fieldName, fieldTypeId);
- _curSchema = _curSchema ?? new ResizeableArray<PortableObjectSchemaField>(4);
-
- _curSchema.Add(new PortableObjectSchemaField(fieldId, _stream.Position - _curPos));
+ _schema.Value.Push(fieldId, _stream.Position - _curPos);
}
/// <summary>