[llvm] Reland '[lineeditor] Add `setHistorySize()` method for adjusting history size' (PR #115442)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 17 03:10:01 PST 2024


https://github.com/devajithvs updated https://github.com/llvm/llvm-project/pull/115442

>From d9237b8ac5ed6ab04f94ccff326c3dd9d707c404 Mon Sep 17 00:00:00 2001
From: Devajith Valaparambil Sreeramaswamy
 <devajith.valaparambil.sreeramaswamy at cern.ch>
Date: Thu, 26 Sep 2024 09:53:41 +0200
Subject: [PATCH] [lineeditor] Add `setHistorySize()` method for adjusting
 history size

---
 llvm/include/llvm/LineEditor/LineEditor.h | 1 +
 llvm/lib/LineEditor/LineEditor.cpp        | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/LineEditor/LineEditor.h b/llvm/include/llvm/LineEditor/LineEditor.h
index 29fdf9f85c6fa5..ca0312bf6297f5 100644
--- a/llvm/include/llvm/LineEditor/LineEditor.h
+++ b/llvm/include/llvm/LineEditor/LineEditor.h
@@ -41,6 +41,7 @@ class LineEditor {
 
   void saveHistory();
   void loadHistory();
+  void setHistorySize(int size);
 
   static std::string getDefaultHistoryPath(StringRef ProgName);
 
diff --git a/llvm/lib/LineEditor/LineEditor.cpp b/llvm/lib/LineEditor/LineEditor.cpp
index d0d138bb1f9d8d..c7d5fd7dcf8ac5 100644
--- a/llvm/lib/LineEditor/LineEditor.cpp
+++ b/llvm/lib/LineEditor/LineEditor.cpp
@@ -17,6 +17,7 @@
 #include <cstdio>
 #ifdef HAVE_LIBEDIT
 #include <histedit.h>
+constexpr int DefaultHistorySize = 800;
 #endif
 
 using namespace llvm;
@@ -220,8 +221,8 @@ LineEditor::LineEditor(StringRef ProgName, StringRef HistoryPath, FILE *In,
            NULL); // Fix the delete key.
   ::el_set(Data->EL, EL_CLIENTDATA, Data.get());
 
+  setHistorySize(DefaultHistorySize);
   HistEvent HE;
-  ::history(Data->Hist, &HE, H_SETSIZE, 800);
   ::history(Data->Hist, &HE, H_SETUNIQUE, 1);
   loadHistory();
 }
@@ -248,6 +249,11 @@ void LineEditor::loadHistory() {
   }
 }
 
+void LineEditor::setHistorySize(int size) {
+  HistEvent HE;
+  ::history(Data->Hist, &HE, H_SETSIZE, size);
+}
+
 std::optional<std::string> LineEditor::readLine() const {
   // Call el_gets to prompt the user and read the user's input.
   int LineLen = 0;
@@ -291,6 +297,7 @@ LineEditor::~LineEditor() {
 
 void LineEditor::saveHistory() {}
 void LineEditor::loadHistory() {}
+void LineEditor::setHistorySize(int size) {}
 
 std::optional<std::string> LineEditor::readLine() const {
   ::fprintf(Data->Out, "%s", Prompt.c_str());



More information about the llvm-commits mailing list