[geary: 4/10] Don't repeat the string search when replacing an inline image source !343



commit e765da347ba13835115ac62499e3fff350474347
Author: Chris Heywood <15127-creywood users noreply gitlab gnome org>
Date:   Sat Oct 26 19:14:17 2019 +0200

    Don't repeat the string search when replacing an inline image source !343

 src/engine/api/geary-composed-email.vala | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/src/engine/api/geary-composed-email.vala b/src/engine/api/geary-composed-email.vala
index 14953e78..418323c2 100644
--- a/src/engine/api/geary-composed-email.vala
+++ b/src/engine/api/geary-composed-email.vala
@@ -90,18 +90,17 @@ public class Geary.ComposedEmail : BaseObject {
     public bool replace_inline_img_src(string orig, string replacement) {
         // XXX This and contains_inline_img_src are pretty
         // hacky. Should probably be working with a DOM tree.
-        bool found = false;
+        int index = -1;
         if (this.body_html != null) {
             string prefixed_orig = IMG_SRC_TEMPLATE.printf(this.img_src_prefix + orig);
-            found = this.body_html.contains(prefixed_orig);
-            if (found) {
-                this.body_html = this.body_html.replace(
-                    prefixed_orig,
-                    IMG_SRC_TEMPLATE.printf(replacement)
-                );
+            index = this.body_html.index_of(prefixed_orig);
+            if (index != -1) {
+                this.body_html = this.body_html.substring(0, index) +
+                     IMG_SRC_TEMPLATE.printf(replacement) +
+                     this.body_html.substring(index + prefixed_orig.length);
             }
         }
-        return found;
+        return index != -1;
     }
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]