mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-03 14:34:08 +02:00
Get rid of string.Split in FileSerializer
string.Split is not suitable for potentially very large strings, so this decently improves memory usage
This commit is contained in:
parent
62449450f3
commit
d06e29db15
@ -103,8 +103,27 @@ public void Read(string file, T obj){
|
|||||||
case 1:
|
case 1:
|
||||||
throw new FormatException("Input appears to be a binary file.");
|
throw new FormatException("Input appears to be a binary file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string contents = UnescapeStream(reader);
|
||||||
|
int currentPos = 0;
|
||||||
|
|
||||||
|
do{
|
||||||
|
string line;
|
||||||
|
int nextPos = contents.IndexOf(NewLineReal, currentPos);
|
||||||
|
|
||||||
foreach(string line in UnescapeStream(reader).Split(new string[]{ NewLineReal }, StringSplitOptions.RemoveEmptyEntries)){
|
if (nextPos == -1){
|
||||||
|
line = contents.Substring(currentPos);
|
||||||
|
currentPos = -1;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(line)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
line = contents.Substring(currentPos, nextPos-currentPos);
|
||||||
|
currentPos = nextPos+NewLineReal.Length;
|
||||||
|
}
|
||||||
|
|
||||||
int space = line.IndexOf(' ');
|
int space = line.IndexOf(' ');
|
||||||
|
|
||||||
if (space == -1){
|
if (space == -1){
|
||||||
@ -115,7 +134,7 @@ public void Read(string file, T obj){
|
|||||||
string value = UnescapeLine(line.Substring(space+1));
|
string value = UnescapeLine(line.Substring(space+1));
|
||||||
|
|
||||||
if (props.TryGetValue(property, out PropertyInfo info)){
|
if (props.TryGetValue(property, out PropertyInfo info)){
|
||||||
if (!converters.TryGetValue(info.PropertyType, out ITypeConverter serializer)) {
|
if (!converters.TryGetValue(info.PropertyType, out ITypeConverter serializer)){
|
||||||
serializer = BasicSerializerObj;
|
serializer = BasicSerializerObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +148,7 @@ public void Read(string file, T obj){
|
|||||||
else{
|
else{
|
||||||
unknownProperties[property] = value;
|
unknownProperties[property] = value;
|
||||||
}
|
}
|
||||||
}
|
}while(currentPos != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unknownProperties.Count > 0){
|
if (unknownProperties.Count > 0){
|
||||||
|
Loading…
Reference in New Issue
Block a user