Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4FCA718136 for ; Mon, 2 Nov 2015 17:21:50 +0000 (UTC) Received: (qmail 54555 invoked by uid 500); 2 Nov 2015 17:21:50 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 54499 invoked by uid 500); 2 Nov 2015 17:21:50 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 54469 invoked by uid 99); 2 Nov 2015 17:21:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2015 17:21:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0678EE0593; Mon, 2 Nov 2015 17:21:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Mon, 02 Nov 2015 17:21:51 -0000 Message-Id: <75facab533dc450492f348259d52ee6a@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/29] ignite git commit: IGNITE-1835 .Net: Use thread-local pool to store schemas in PortableWriter IGNITE-1835 .Net: Use thread-local pool to store schemas in PortableWriter Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/12a4a97d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/12a4a97d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/12a4a97d Branch: refs/heads/ignite-950-new Commit: 12a4a97dd322b6de542a048e971adff077b85b9f Parents: 2cdbb2f Author: Pavel Tupitsyn Authored: Mon Nov 2 15:40:42 2015 +0300 Committer: Pavel Tupitsyn Committed: Mon Nov 2 15:40:42 2015 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.csproj | 1 + .../Impl/Portable/PortableObjectSchemaField.cs | 7 ++- .../Impl/Portable/PortableObjectSchemaHolder.cs | 64 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/12a4a97d/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj index ffe5d9f..d782aec 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj @@ -258,6 +258,7 @@ + http://git-wip-us.apache.org/repos/asf/ignite/blob/12a4a97d/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs index 48fd9c1..b8ed62f 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaField.cs @@ -53,8 +53,9 @@ namespace Apache.Ignite.Core.Impl.Portable /// /// Fields. /// Stream. + /// Start index. /// Field count to write. - public static unsafe void WriteArray(PortableObjectSchemaField[] fields, IPortableStream stream, int count) + public static unsafe void WriteArray(PortableObjectSchemaField[] fields, IPortableStream stream, int start, int count) { Debug.Assert(fields != null); Debug.Assert(stream != null); @@ -64,12 +65,12 @@ namespace Apache.Ignite.Core.Impl.Portable { fixed (PortableObjectSchemaField* ptr = &fields[0]) { - stream.Write((byte*) ptr, count * Size); + stream.Write((byte*) ptr + start * Size, count * Size); } } else { - for (int i = 0; i < count; i++) + for (int i = start; i < count + start; i++) { var field = fields[i]; http://git-wip-us.apache.org/repos/asf/ignite/blob/12a4a97d/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 new file mode 100644 index 0000000..daf325c --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Portable/PortableObjectSchemaHolder.cs @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Impl.Portable +{ + using System; + using System.Diagnostics; + using Apache.Ignite.Core.Impl.Portable.IO; + + /// + /// Shared schema holder. + /// + internal class PortableObjectSchemaHolder + { + /** Fields. */ + private PortableObjectSchemaField[] _fields = new PortableObjectSchemaField[16]; + + /** Current field index. */ + private int _idx = 0; + + /// + /// Adds a field to the holder. + /// + /// The identifier. + /// The offset. + public void Push(int id, int offset) + { + if (_idx == _fields.Length) + Array.Resize(ref _fields, _fields.Length * 2); + + _fields[_idx] = new PortableObjectSchemaField(id, offset); + + _idx++; + } + + /// + /// Writes specified number of collected fields and removes them/ + /// + /// The stream. + /// The count. + public void WriteAndPop(IPortableStream stream, int count) + { + Debug.Assert(count <= _idx); + + PortableObjectSchemaField.WriteArray(_fields, stream, _idx - count, count); + + _idx -= count; + } + } +}