From 42e9f0cf58dd4aad1d4168013e13448cc44cf3a3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 Aug 2017 17:28:00 +0200 Subject: [PATCH] Make wxGTK wxTextCtrl::WriteText() less inefficient Use wxScopedCharBuffer as we only need the buffer in the current scope. This avoids a buffer copy done by wxCharBuffer which could be a significant pessimization for large buffers. Also don't call strlen() unnecessarily, we already know the buffer length, so just use it. --- src/gtk/textctrl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 986cf6c328..235b371c46 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1056,7 +1056,7 @@ void wxTextCtrl::WriteText( const wxString &text ) } #if wxUSE_UNICODE - const wxCharBuffer buffer(text.utf8_str()); + const wxScopedCharBuffer buffer(text.utf8_str()); #else // check if we have a specific style for the current position wxFontEncoding enc = wxFONTENCODING_SYSTEM; @@ -1069,7 +1069,7 @@ void wxTextCtrl::WriteText( const wxString &text ) if ( enc == wxFONTENCODING_SYSTEM ) enc = GetTextEncoding(); - const wxCharBuffer buffer(wxGTK_CONV_ENC(text, enc)); + const wxScopedCharBuffer buffer(wxGTK_CONV_ENC(text, enc)); if ( !buffer ) { // we must log an error here as losing the text like this can be a @@ -1088,7 +1088,7 @@ void wxTextCtrl::WriteText( const wxString &text ) gtk_text_buffer_get_iter_at_mark( m_buffer, &iter, gtk_text_buffer_get_insert (m_buffer) ); - gtk_text_buffer_insert( m_buffer, &iter, buffer, strlen(buffer) ); + gtk_text_buffer_insert( m_buffer, &iter, buffer, buffer.length() ); // Scroll to cursor, but only if scrollbar thumb is at the very bottom // won't work when frozen, text view is not using m_buffer then