[pdfmod] Make removing many pages much faster (bgo#630012)



commit b89cf345336aa5a0f6953d4f0d8419f43c4cd06f
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Mar 3 12:00:59 2011 -0600

    Make removing many pages much faster (bgo#630012)
    
    We were removing each page one at a time before; now do them in one go.

 src/PdfMod/Pdf/Actions/RemoveAction.cs |   16 +++++-----------
 1 files changed, 5 insertions(+), 11 deletions(-)
---
diff --git a/src/PdfMod/Pdf/Actions/RemoveAction.cs b/src/PdfMod/Pdf/Actions/RemoveAction.cs
index 4ea6b5e..0cfafc6 100644
--- a/src/PdfMod/Pdf/Actions/RemoveAction.cs
+++ b/src/PdfMod/Pdf/Actions/RemoveAction.cs
@@ -1,5 +1,6 @@
 
 using System;
+using System.Linq;
 using System.Collections.Generic;
 
 using Mono.Unix;
@@ -13,10 +14,12 @@ namespace PdfMod.Pdf.Actions
 {
     public class RemoveAction : BasePageAction
     {
-        int [] old_indices;
+        //int [] old_indices;
+        Page [] pages;
 
         public RemoveAction (Document document, IEnumerable<Page> pages) : base (document, pages)
         {
+            this.pages = pages.ToArray ();
         }
 
         public override void Undo ()
@@ -37,16 +40,7 @@ namespace PdfMod.Pdf.Actions
 
         public override void Redo ()
         {
-            if (old_indices != null) {
-                throw new InvalidOperationException (Catalog.GetString ("Error trying to remove pages from document"));
-            }
-
-            old_indices = new int[Pages.Count];
-            for (int i = 0; i < Pages.Count; i++) {
-                old_indices[i] = Document.IndexOf (Pages[i]);
-                Console.WriteLine ("Old index of {0} was {1}", Pages[i], old_indices[i]);
-                Document.Remove (Pages[i]);
-            }
+            Document.Remove (pages);
         }
     }
 }



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