Skip to content

Commit f5bcda9

Browse files
committed
Use string instead of StringBuffer in HistoryItem
1 parent 6b2acc9 commit f5bcda9

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

PSReadLine/ReadLine.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ class KeyHandler
9191
public string LongDescription;
9292
}
9393

94-
[DebuggerDisplay("{_buffer}")]
94+
[DebuggerDisplay("{_line}")]
9595
class HistoryItem
9696
{
97-
public StringBuilder _buffer;
97+
public string _line;
9898
}
9999

100100
static KeyHandler MakeKeyHandler(Action<ConsoleKeyInfo?, object> action, string briefDescription, string longDescription = null)
@@ -367,7 +367,7 @@ private string MaybeAddToHistory(string result)
367367
}
368368
if (addToHistory)
369369
{
370-
_history.Enqueue(new HistoryItem { _buffer = new StringBuilder(_buffer.ToString()) });
370+
_history.Enqueue(new HistoryItem { _line = _buffer.ToString() });
371371
_currentHistoryIndex = _history.Count;
372372
}
373373
if (_demoMode)
@@ -381,15 +381,15 @@ private void HistoryOnEnqueueHandler(HistoryItem obj)
381381
{
382382
if (_historyNoDuplicates)
383383
{
384-
_hashedHistory.Add(obj._buffer.ToString());
384+
_hashedHistory.Add(obj._line);
385385
}
386386
}
387387

388388
private void HistoryOnDequeueHandler(HistoryItem obj)
389389
{
390390
if (_historyNoDuplicates)
391391
{
392-
_hashedHistory.Remove(obj._buffer.ToString());
392+
_hashedHistory.Remove(obj._line);
393393
}
394394
}
395395

@@ -492,7 +492,7 @@ private PSConsoleReadLine()
492492
_chordDispatchTable = new Dictionary<ConsoleKeyInfo, Dictionary<ConsoleKeyInfo, KeyHandler>>();
493493

494494
_buffer = new StringBuilder();
495-
_savedCurrentLine = new HistoryItem {_buffer = new StringBuilder()};
495+
_savedCurrentLine = new HistoryItem();
496496

497497
_tokenForegroundColors = new ConsoleColor[(int)TokenClassification.Member + 1];
498498
_tokenBackgroundColors = new ConsoleColor[_tokenForegroundColors.Length];
@@ -860,11 +860,11 @@ public static void ClearHistory()
860860

861861
private void UpdateFromHistory(bool moveCursor)
862862
{
863-
var buffer = (_currentHistoryIndex == _history.Count)
864-
? _savedCurrentLine._buffer
865-
: _history[_currentHistoryIndex]._buffer;
863+
var line = (_currentHistoryIndex == _history.Count)
864+
? _savedCurrentLine._line
865+
: _history[_currentHistoryIndex]._line;
866866
_buffer.Clear();
867-
_buffer.Append(buffer);
867+
_buffer.Append(line);
868868
if (moveCursor)
869869
{
870870
_current = _buffer.Length;
@@ -876,8 +876,7 @@ private void SaveCurrentLine()
876876
{
877877
if (_singleton._currentHistoryIndex == _history.Count)
878878
{
879-
_savedCurrentLine._buffer.Clear();
880-
_savedCurrentLine._buffer.Append(_buffer.ToString());
879+
_savedCurrentLine._line = _buffer.ToString();
881880
}
882881
}
883882

@@ -918,7 +917,7 @@ private void HistorySearch(bool backward)
918917
int incr = backward ? -1 : +1;
919918
for (int i = _currentHistoryIndex + incr; i >=0 && i < _history.Count; i += incr)
920919
{
921-
if (_history[i]._buffer.ToString().StartsWith(_searchHistoryPrefix))
920+
if (_history[i]._line.StartsWith(_searchHistoryPrefix))
922921
{
923922
_currentHistoryIndex = i;
924923
UpdateFromHistory(moveCursor: _historySearchCursorMovesToEnd);
@@ -1995,7 +1994,7 @@ private void SetOptionsInternal(SetPSReadlineOption options)
19951994
while (_history.Count > 0)
19961995
{
19971996
var item = _history.Dequeue();
1998-
var itemStr = item._buffer.ToString();
1997+
var itemStr = item._line;
19991998
if (!_hashedHistory.Contains(itemStr))
20001999
{
20012000
newHistory.Enqueue(item);

0 commit comments

Comments
 (0)