[svn] r7559: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n

kliss svnadmin at nemerle.org
Wed Mar 28 23:50:07 CEST 2007


Log:
Improve performance.
- Use SCG.List instead of list when merging highlighting lists. 
- Use Hashtable[K, V].GetValueOrDefault(key : K, default : V) instead of .Get(key : K)

Author: kliss
Date: Wed Mar 28 23:50:05 2007
New Revision: 7559

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n	Wed Mar 28 23:50:05 2007
@@ -7,6 +7,7 @@
 using TP = Nemerle.Completion2.ScanTokenType;
 using C  = Nemerle.Completion2.ScanTokenColor;
 using TR = Nemerle.Completion2.ScanTokenTriggers;
+using SCG = System.Collections.Generic;
 
 namespace Nemerle.Completion2
 {
@@ -805,26 +806,25 @@
     
     GetHighlightsForLine(line : int) : list[Location * int]
     {
-      /* kliss: This method may be not very efficient, just tell me 
-        what is the most efficient way to merge several lists. */
       def mergeWithResult(result, newValue)
       {
         match(newValue)
         {
-        | Some(val) => result.Append(val);
-        | None => result;
+        | x :: xs => result.Add(x); mergeWithResult(result, xs);
+        | _ => ();
         }
       }
       // Getting hovered highlights
-      mutable result = mergeWithResult([], hoverHighlightedLocations.Get(line));
+      def result = SCG.List();
+      mergeWithResult(result, hoverHighlightedLocations.GetValueOrDefault(line, null));
       
       // Getting permanent highlights
       foreach(stackedHighlight in permanentHighlights)
       {
-        result = mergeWithResult(result, stackedHighlight.Get(line));
+        mergeWithResult(result, stackedHighlight.GetValueOrDefault(line, null));
       }
       
-      result;
+      result.ToList();
     }
     
     AddHighlightsOnTheLine(table : Hashtable[int, list[Location * int]], 



More information about the svn mailing list