diff options
| author | Andrey Sukharev <SukharevAndrey@users.noreply.github.com> | 2023-01-19 01:25:16 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-18 22:25:16 +0000 |
| commit | ae4324032a48ee08a808354673f47536e76759d0 (patch) | |
| tree | 90c7c6aceb14d095761a257a41e7dc6882d30d73 /Ryujinx.HLE/HOS/Diagnostics | |
| parent | f449895e6d8af90f727de6590fd6120038c73986 (diff) | |
Optimize string memory usage. Use Spans and StringBuilders where possible (#3933)
* Optimize string memory usage. Use ReadOnlySpan<char> and StringBuilder where possible.
* Fix copypaste error
* Code generator review fixes
* Use if statement instead of switch
* Code style fixes
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Another code style fix
* Styling fix
Co-authored-by: Mary-nyan <thog@protonmail.com>
* Styling fix
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Mary-nyan <thog@protonmail.com>
Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Diffstat (limited to 'Ryujinx.HLE/HOS/Diagnostics')
| -rw-r--r-- | Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs | 3 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs | 26 |
2 files changed, 15 insertions, 14 deletions
diff --git a/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs b/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs index 951faa55..ea048d76 100644 --- a/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs +++ b/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/IntegerLiteral.cs @@ -1,4 +1,5 @@ using System.IO; +using System; namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast { @@ -25,7 +26,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast if (_literalValue[0] == 'n') { writer.Write("-"); - writer.Write(_literalValue.Substring(1)); + writer.Write(_literalValue.AsSpan(1)); } else { diff --git a/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs b/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs index be5b7539..a6618eca 100644 --- a/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs +++ b/Ryujinx.HLE/HOS/Diagnostics/Demangler/Demangler.cs @@ -32,9 +32,9 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private bool ConsumeIf(string toConsume) { - string mangledPart = Mangled.Substring(_position); + var mangledPart = Mangled.AsSpan(_position); - if (mangledPart.StartsWith(toConsume)) + if (mangledPart.StartsWith(toConsume.AsSpan())) { _position += toConsume.Length; @@ -44,14 +44,14 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return false; } - private string PeekString(int offset = 0, int length = 1) + private ReadOnlySpan<char> PeekString(int offset = 0, int length = 1) { if (_position + offset >= length) { return null; } - return Mangled.Substring(_position + offset, length); + return Mangled.AsSpan(_position + offset, length); } private char Peek(int offset = 0) @@ -101,8 +101,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private int ParseSeqId() { - string part = Mangled.Substring(_position); - int seqIdLen = 0; + ReadOnlySpan<char> part = Mangled.AsSpan(_position); + int seqIdLen = 0; for (; seqIdLen < part.Length; seqIdLen++) { @@ -114,7 +114,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler _position += seqIdLen; - return FromBase36(part.Substring(0, seqIdLen)); + return FromBase36(new string(part[..seqIdLen])); } // <substitution> ::= S <seq-id> _ @@ -900,8 +900,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler private int ParsePositiveNumber() { - string part = Mangled.Substring(_position); - int numberLength = 0; + ReadOnlySpan<char> part = Mangled.AsSpan(_position); + int numberLength = 0; for (; numberLength < part.Length; numberLength++) { @@ -918,7 +918,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return -1; } - return int.Parse(part.AsSpan(0, numberLength)); + return int.Parse(part[..numberLength]); } private string ParseNumber(bool isSigned = false) @@ -933,8 +933,8 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler return null; } - string part = Mangled.Substring(_position); - int numberLength = 0; + ReadOnlySpan<char> part = Mangled.AsSpan(_position); + int numberLength = 0; for (; numberLength < part.Length; numberLength++) { @@ -946,7 +946,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler _position += numberLength; - return part.Substring(0, numberLength); + return new string(part[..numberLength]); } // <source-name> ::= <positive length number> <identifier> |
