gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r9263 - Extractor-mono/LibExtractor/src


From: gnunet
Subject: [GNUnet-SVN] r9263 - Extractor-mono/LibExtractor/src
Date: Sat, 24 Oct 2009 07:42:55 -0600

Author: patrick
Date: 2009-10-24 07:42:55 -0600 (Sat, 24 Oct 2009)
New Revision: 9263

Modified:
   Extractor-mono/LibExtractor/src/Extractor.cs
Log:
* src/Extractor.cs: made some more methods less resource intensive, removed 
commented code

Modified: Extractor-mono/LibExtractor/src/Extractor.cs
===================================================================
--- Extractor-mono/LibExtractor/src/Extractor.cs        2009-10-23 23:36:08 UTC 
(rev 9262)
+++ Extractor-mono/LibExtractor/src/Extractor.cs        2009-10-24 13:42:55 UTC 
(rev 9263)
@@ -200,10 +200,14 @@
                                           ( ((options & 
DuplicateOptions.DUPLICATES_REMOVE_UNKNOWN) > 0) &&
                                             (pos.keywordType == 
KeywordType.EXTRACTOR_UNKNOWN)) ) ) {
                                                
-                                               // do not modify the original 
array
-                                               if (removed == 0)
+                                               if (removed == 0) {
+                                                       // do not modify the 
original array.
+                                                       // lazy copy - copy 
only if the array
+                                                       // will be modified.
                                                        keywords = 
CopyKeywords(keywords);
+                                               }
                                                
+                                               // mark keyword as removed.
                                                keywords[j] = null;
                                                removed++;
                                        }
@@ -213,44 +217,8 @@
                        return RemoveNullKeywords(keywords, removed);
                }
                
-               /*
-               public static Keyword[] RemoveDuplicateKeywords(Keyword[] 
keywords, DuplicateOptions options) {
-                       List<Keyword> lst = new List<Keyword>();
-
-                       for (int i = 0; i < keywords.Length; i++) {
-                               Keyword pos     = keywords[i];
-                               bool remove     = false;
-                               
-                               for (int j = 0; j < lst.Count; j++) {           
                        
-                                       KeywordType type        = 
lst[j].keywordType;
-                                       string keyword          = 
lst[j].keyword;
-                                       
-                                       if ( (pos.keyword == keyword) &&
-                                        ( (pos.keywordType == type) ||
-                                          ( ((options & 
DuplicateOptions.DUPLICATES_TYPELESS) > 0) &&
-                                            ( (pos.keywordType == 
KeywordType.EXTRACTOR_SPLIT) ||
-                                              (type != 
KeywordType.EXTRACTOR_SPLIT)) ) ||
-                                          ( ((options & 
DuplicateOptions.DUPLICATES_REMOVE_UNKNOWN) > 0) &&
-                                            (pos.keywordType == 
KeywordType.EXTRACTOR_UNKNOWN)) ) ) {
-                                               remove = true;
-                                               break; // break inner for
-                                       }
-                               }
-                               
-                               if (!remove) {
-                                       lst.Add(pos);
-                               }
-                       }
-                       
-                       if (lst.Count == keywords.Length)
-                               return keywords;
-                       else
-                               return lst.ToArray();
-               }
-               */
-               
                public static Keyword[] RemoveEmptyKeywords(Keyword[] keywords) 
{
-                       List<Keyword> lst = new List<Keyword>();
+                       List<Keyword> lst = null;
                        
                        for (int i = 0; i < keywords.Length; i++) {
                                Keyword pos = keywords[i];
@@ -264,27 +232,41 @@
                                        }
                                }
                                
-                               if (!allWhite)
-                                       lst.Add(pos);
+                               if (allWhite) {
+                                       if (lst == null) {
+                                               // lazy copy -
+                                               // copy only if keywords will 
actually be removed.
+                                               lst = new 
List<Keyword>(keywords.Length);
+                                               lst.AddRange(keywords);
+                                       }
+                                       lst.Remove(pos);
+                               }
                        }
                        
-                       if (lst.Count == keywords.Length)
+                       if (lst == null)
                                return keywords;
                        else
                                return lst.ToArray();
                }
                
                public static Keyword[] RemoveKeywordsOfType(Keyword[] 
keywords, KeywordType type) {
-                       List<Keyword> lst = new List<Keyword>();
+                       List<Keyword> lst = null;
                        
                        for (int i = 0; i < keywords.Length; i++) {
                                Keyword pos = keywords[i];
-                               if (pos.keywordType != type) {
-                                       lst.Add(pos);
+                               
+                               if (pos.keywordType == type) {
+                                       if (lst == null) {
+                                               // lazy copy -
+                                               // copy only if keywords will 
actually be removed.
+                                               lst = new 
List<Keyword>(keywords.Length);
+                                               lst.AddRange(keywords);
+                                       }
+                                       lst.Remove(pos);
                                }
                        }
                        
-                       if (lst.Count == keywords.Length)
+                       if (lst == null)
                                return keywords;
                        else
                                return lst.ToArray();





reply via email to

[Prev in Thread] Current Thread [Next in Thread]