Skip to content
Permalink
Browse files

don't use fixed (char*

  • Loading branch information...
UnknownShadow200 committed Sep 2, 2018
1 parent 97df064 commit 36489b59c538c000a5ee49a202bce42ebf4f0264
Showing with 13 additions and 15 deletions.
  1. +0 −1 fCraft/Player/Player.cs
  2. +13 −14 fCraft/Player/PlayerDB.cs
@@ -155,7 +155,6 @@ public sealed partial class Player : IClassy {
public string PortalWorld;
public Position PortalTPPos;
public string PortalName;
public bool BuildingPortal = true;
public DateTime LastUsedPortal;
public DateTime LastWarnedPortal;
public bool PortalsEnabled = true;
@@ -220,23 +220,22 @@ public static class PlayerDB {
unsafe static void Split(string line, ref string[] fields, out int count) {
// Effectively string.split(',') but without the two passes and memory allocations.
count = 0;
fixed (char* ptr = line) {
int start = 0, len = 0;
for (int i = 0; i < line.Length; i++) {
if (ptr[i] != ',') { len++; continue; }
if (count == fields.Length)
Array.Resize(ref fields, count + 10);
fields[count] = len == 0 ? "" : new String(ptr, start, len); count++;
// Start next string at character after the ,
start = i + 1;
len = 0;
}

// We will always have at least one string, even if it just empty.
int start = 0, len = 0;
for (int i = 0; i < line.Length; i++) {
if (line[i] != ',') { len++; continue; }
if (count == fields.Length)
Array.Resize(ref fields, count + 10);
fields[count] = len == 0 ? "" : new String(ptr, start, len); count++;

fields[count] = line.Substring(start, len); count++;
// Start next string at character after the ,
start = i + 1;
len = 0;
}

// We will always have at least one string, even if it just empty.
if (count == fields.Length)
Array.Resize(ref fields, count + 10);
fields[count] = line.Substring(start, len); count++;
}


0 comments on commit 36489b5

Please sign in to comment.
You can’t perform that action at this time.