We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 80cefba commit da3321fCopy full SHA for da3321f
tools/line_editor.cc
@@ -9,6 +9,7 @@
9
#include <unistd.h>
10
#endif
11
#include <cstdio>
12
+#include <algorithm>
13
14
LineEditor::LineEditor(size_t max_length) : max_length_(max_length) {}
15
@@ -68,9 +69,13 @@ bool LineEditor::ReadLine(std::string* out) {
68
69
}
70
71
if (!whitespace_only) {
- if (history_.empty() || history_.back() != *out) {
72
+ const auto it = std::find(history_.begin(), history_.end(), *out);
73
+ if (it == history_.end()) {
74
history_.push_back(*out);
75
76
+ if (history_.size() > 4096) {
77
+ history_.erase(history_.begin());
78
+ }
79
80
81
suggestion_.clear();
0 commit comments