From 97d73e54afb80246e953ec0e2538e3b050e4c20f Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Mon, 27 Mar 2017 13:47:53 +0300 Subject: [PATCH] Microoptimization + code cleanup --- WhiteRabbit/Phrase.cs | 11 +++-------- WhiteRabbit/StringsProcessor.cs | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/WhiteRabbit/Phrase.cs b/WhiteRabbit/Phrase.cs index 6ec3ada..c5635e1 100644 --- a/WhiteRabbit/Phrase.cs +++ b/WhiteRabbit/Phrase.cs @@ -2,8 +2,6 @@ { internal unsafe struct Phrase { - private const byte SPACE = 32; - public fixed byte Buffer[32]; public Phrase(byte[][] words, int numberOfCharacters) @@ -20,16 +18,13 @@ { if (j >= currentWord.Length) { - *currentPointer = SPACE; j = 0; wordIndex++; currentWord = words[wordIndex]; } - else - { - *currentPointer = currentWord[j]; - j++; - } + + *currentPointer = currentWord[j]; + j++; } bufferPointer[31] = (byte)length; diff --git a/WhiteRabbit/StringsProcessor.cs b/WhiteRabbit/StringsProcessor.cs index a3cd74f..d971c24 100644 --- a/WhiteRabbit/StringsProcessor.cs +++ b/WhiteRabbit/StringsProcessor.cs @@ -17,7 +17,7 @@ // Dictionary of vectors to array of words represented by this vector var vectorsToWords = words .Where(word => word != null && word.Length > 0) - .Select(word => new { word, vector = this.VectorsConverter.GetVector(word) }) + .Select(word => new { word = word.Concat(new byte[] { SPACE }).ToArray(), vector = this.VectorsConverter.GetVector(word) }) .Where(tuple => tuple.vector != null) .Select(tuple => new { tuple.word, vector = tuple.vector.Value }) .GroupBy(tuple => tuple.vector)