Skip to content

Commit

Permalink
Fixed bug in ParseLinesUnsafe where only a part of the line would be …
Browse files Browse the repository at this point in the history
…parsed leading to wrong results.
  • Loading branch information
Alois-xx committed Nov 21, 2018
1 parent 960ad26 commit 3b0d30a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -165,8 +166,7 @@ private unsafe static uint ReadFileIntoByteBuffer(string dataFile)

/// <summary>
/// Read the file line by line and count the lines.
/// This is very fast because one never allocates long living objects. We always
/// need only one line in memory.
/// This is very fast because one never allocates long living objects.
/// </summary>
private static int CountLines(string dataFile)
{
Expand Down Expand Up @@ -334,6 +334,7 @@ unsafe private static void ParseLinesUnsafe(string dataFile)
{
var dobules = new List<double>();
var ints = new List<int>();
char decimalChar = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0];

using (var reader = new StreamReader(dataFile))
{
Expand All @@ -344,14 +345,17 @@ unsafe private static void ParseLinesUnsafe(string dataFile)
while ((line = reader.ReadLine()) != null)
{
int len = line.Length;
ix = 0;
a = 0;
b = 0;
fixed (char* ln = line)
{
while (ix < len && char.IsNumber(ln[ix]))
{
a = a * 10 + (ln[ix++] - '0');
}

if (ln[ix] == ',')
if (ln[ix] == decimalChar)
{
ix++;
long div = 1;
Expand All @@ -375,7 +379,7 @@ unsafe private static void ParseLinesUnsafe(string dataFile)
}

dobules.Add(d);
ints.Add(ix);
ints.Add(i);
}
}
}
Expand Down
Binary file modified src/images/OverView.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3b0d30a

Please sign in to comment.