From e9d7d70e47fd57476797508cc3ee415c54e86646 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 1 Sep 2015 13:59:40 +0100 Subject: [PATCH] Cache buffer display name --- src/buffer.cc | 16 ++++++++-------- src/buffer.hh | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 3f76f20c..0685e5b3 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -20,7 +20,8 @@ namespace Kakoune Buffer::Buffer(String name, Flags flags, BufferLines lines, time_t fs_timestamp) : Scope(GlobalScope::instance()), - m_name(flags & Flags::File ? real_path(parse_filename(name)) : std::move(name)), + m_name((flags & Flags::File) ? real_path(parse_filename(name)) : std::move(name)), + m_display_name((flags & Flags::File) ? compact_path(m_name) : m_name), m_flags(flags | Flags::NoUndo), m_history(), m_history_cursor(m_history.begin()), m_last_save_undo_index(0), @@ -71,22 +72,21 @@ Buffer::~Buffer() m_values.clear(); } -String Buffer::display_name() const -{ - if (m_flags & Flags::File) - return compact_path(m_name); - return m_name; -} - bool Buffer::set_name(String name) { Buffer* other = BufferManager::instance().get_buffer_ifp(name); if (other == nullptr or other == this) { if (m_flags & Flags::File) + { m_name = real_path(name); + m_display_name = compact_path(m_name); + } else + { m_name = std::move(name); + m_display_name = m_name; + } return true; } return false; diff --git a/src/buffer.hh b/src/buffer.hh index 9a0525d5..ba5a62df 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -139,7 +139,7 @@ public: ByteCoordAndTarget offset_coord(ByteCoordAndTarget coord, LineCount offset); const String& name() const { return m_name; } - String display_name() const; + const String& display_name() const { return m_display_name; } // returns true if the buffer is in a different state than // the last time it was saved @@ -199,6 +199,7 @@ private: LineList m_lines; String m_name; + String m_display_name; Flags m_flags; using UndoGroup = Vector;