Microoptimization

master
Inga 🏳‍🌈 8 years ago
parent b667aa8830
commit 5ffaa1090a
  1. 15
      dotnet/WhiteRabbit/PhraseSet.cs
  2. 2
      dotnet/WhiteRabbit/Program.cs
  3. 8
      dotnet/WhiteRabbit/StringsProcessor.cs

@ -10,21 +10,18 @@
{
private uint[] Buffer;
public int Length;
public PhraseSet(int length)
public void Init()
{
this.Length = length;
this.Buffer = new uint[8 * length];
this.Buffer = new uint[8 * Constants.PhrasesPerSet];
}
public unsafe void InitPhraseSet(int numberOfCharacters, int numberOfWords)
public unsafe void FillLength(int numberOfCharacters, int numberOfWords)
{
fixed (uint* bufferPointer = this.Buffer)
{
var length = (uint)(numberOfCharacters + numberOfWords - 1);
var lengthInBits = (uint)(length << 3);
for (var i = 0; i < this.Length; i++)
for (var i = 0; i < Constants.PhrasesPerSet; i++)
{
bufferPointer[7 + i * 8] = lengthInBits;
((byte*)bufferPointer)[length + i * 32] = 128 ^ ' ';
@ -71,7 +68,7 @@
public unsafe byte[] GetBytes(int number)
{
Debug.Assert(number < this.Length);
Debug.Assert(number < Constants.PhrasesPerSet);
fixed (uint* bufferPointer = this.Buffer)
{
@ -98,7 +95,7 @@
public unsafe string DebugBytes(int number)
{
Debug.Assert(number < this.Length);
Debug.Assert(number < Constants.PhrasesPerSet);
fixed (uint* bufferPointer = this.Buffer)
{

@ -86,7 +86,7 @@
private static void ProcessPhraseSet(PhraseSet phraseSet, Vector<uint> expectedHashesFirstComponents, Stopwatch stopwatch)
{
phraseSet.ComputeMD5();
for (var i = 0; i < phraseSet.Length; i++)
for (var i = 0; i < Constants.PhrasesPerSet; i++)
{
/*Debug.Assert(
sourceChars == ToOrderedChars(ToString(phraseSet, i)),

@ -120,9 +120,11 @@
private void ProcessSum(int[] sum, Action<PhraseSet> action)
{
var initialPhraseSet = new PhraseSet(Constants.PhrasesPerSet);
initialPhraseSet.InitPhraseSet(this.NumberOfCharacters, sum.Length);
var phraseSet = new PhraseSet(Constants.PhrasesPerSet);
var initialPhraseSet = new PhraseSet();
initialPhraseSet.Init();
initialPhraseSet.FillLength(this.NumberOfCharacters, sum.Length);
var phraseSet = new PhraseSet();
phraseSet.Init();
var filter = ComputeFilter(sum);
var wordsVariants = this.ConvertVectorsToWordIndexes(sum);
foreach (var wordsArray in Flattener.Flatten(wordsVariants))

Loading…
Cancel
Save