aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--configure.ac5
-rw-r--r--src/cmdline.cpp15
2 files changed, 18 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 77b71a7..e2f230f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -94,6 +94,11 @@ case $host in
;;
esac
+# Check for optional GNU libc features.
+# Will probably only be found on Linux.
+AC_CHECK_HEADERS([malloc.h])
+AC_CHECK_FUNCS([malloc_trim])
+
#
# Config options
#
diff --git a/src/cmdline.cpp b/src/cmdline.cpp
index 83a90b4..599a469 100644
--- a/src/cmdline.cpp
+++ b/src/cmdline.cpp
@@ -19,6 +19,10 @@
#include "config.h"
#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
#include <string.h>
#include <signal.h>
@@ -446,10 +450,17 @@ Cmdline::process_edit_cmd(gchar key)
str = NULL;
len = rubout_len = 0;
+#ifdef HAVE_MALLOC_TRIM
/*
- * FIXME: Perhaps to the malloc_trim() here
- * instead of in UndoStack::clear()
+ * Glibc/Linux-only optimization: Undo stacks can grow very
+ * large - sometimes large enough to make the system
+ * swap and become unresponsive.
+ * This will often reduce the amount of memory previously
+ * freed that's still allocated to the program immediately
+ * when the command-line is terminated:
*/
+ malloc_trim(0);
+#endif
} else {
insert(key);
}