[[nbpython-commits]] [hg] main/contrib: More efficient storage of covered lines for p...

  • From: Tor Norbye < >
  • To:
  • Subject: [[nbpython-commits]] [hg] main/contrib: More efficient storage of covered lines for p...
  • Date: Thu, 21 Oct 2010 08:34:26 -0700

changeset d5453c9a85ea in main/contrib
details: http://hg.netbeans.org/main/contrib?cmd=changeset;node=d5453c9a85ea
description:
        More efficient storage of covered lines for python; unlike Ruby, it 
doesn't have line counts so we don't need to store (and parse, and represent 
internally) the counts, only the line numbers.

diffstat:

 python.editor/scripts/coverage_wrapper.py                                    
                 |   2 +-
 
python.editor/src/org/netbeans/modules/python/editor/codecoverage/PythonCoverageProvider.java
 |  81 ++-------
 2 files changed, 21 insertions(+), 62 deletions(-)

diffs (151 lines):

diff --git a/python.editor/scripts/coverage_wrapper.py 
b/python.editor/scripts/coverage_wrapper.py
--- a/python.editor/scripts/coverage_wrapper.py
+++ b/python.editor/scripts/coverage_wrapper.py
@@ -33,7 +33,7 @@
         output_file.write(k.__str__())
         output_file.write('\n')
         x = c1_dict.get(k)
-        output_file.write(x.__str__())
+        output_file.write(x.keys().__str__())
         output_file.write('\n')
 
     output_file.close()
diff --git 
a/python.editor/src/org/netbeans/modules/python/editor/codecoverage/PythonCoverageProvider.java
 
b/python.editor/src/org/netbeans/modules/python/editor/codecoverage/PythonCoverageProvider.java
--- 
a/python.editor/src/org/netbeans/modules/python/editor/codecoverage/PythonCoverageProvider.java
+++ 
b/python.editor/src/org/netbeans/modules/python/editor/codecoverage/PythonCoverageProvider.java
@@ -128,22 +128,18 @@
             }
 
             // Compute coverage:
-            List<LineCount> counts = getLineCounts(entry.getValue());
+            List<Integer> linenos = getLineCounts(entry.getValue());
             int lineCount = 0;
             int executed = 0;
             //int notExecuted = 0;
             //int inferred = 0;
-            for (LineCount lc : counts) {
-                if (lc.lineno > lineCount) {
-                    lineCount = lc.lineno;
+            for (Integer lineno : linenos) {
+                int line = lineno.intValue();
+                if (line > lineCount) {
+                    lineCount = lineno;
                 }
-                if (lc.count > 0) {
-                    executed++;
-                    //} else if (lc.count == COUNT_NOT_COVERED) {
-                    //    notExecuted++;
-                    //} else if (lc.count == COUNT_INFERRED) {
-                    //    inferred++;
-                }
+                // The lines explicitly listed are executed
+                executed++;
             }
 
             //int executed = lineCount - notExecuted;
@@ -236,11 +232,11 @@
         }
 
         if (lines != null) {
-            List<LineCount> hits = getLineCounts(lines);
+            List<Integer> linenos = getLineCounts(lines);
             int max = 0;
-            for (LineCount lineCount : hits) {
-                if (lineCount.lineno > max) {
-                    max = lineCount.lineno;
+            for (Integer lineno : linenos) {
+                if (lineno > max) {
+                    max = lineno;
                 }
             }
 
@@ -248,9 +244,8 @@
             for (int i = 0; i < max; i++) {
                 result[i] = COUNT_UNKNOWN;
             }
-            for (LineCount lineCount : hits) {
-                assert lineCount.lineno > 0;
-                result[lineCount.lineno - 1] = lineCount.count;
+            for (Integer lineno : linenos) {
+                result[lineno - 1] = 1;
             }
 
             inferCounts(result, doc);
@@ -273,22 +268,18 @@
         return new File(getNbCoverageDir(), ".coverage"); // NOI18N
     }
 
-    private List<LineCount> getLineCounts(String lines) {
+    private List<Integer> getLineCounts(String lines) {
         int size = lines.length() / 6;
-        List<LineCount> lineCounts = new ArrayList<LineCount>(size);
+        List<Integer> lineCounts = new ArrayList<Integer>(size);
 
         int start = 1;
         int i = start;
         int length = lines.length();
-        int line = 0;
         while (i < length) {
             char c = lines.charAt(i);
-            if (c == ':') {
-                line = Integer.valueOf(lines.substring(start, i));
-                start = i + 1;
-            } else if (c == ',' || c == '}') {
-                int count = Integer.valueOf(lines.substring(start, i));
-                lineCounts.add(new LineCount(line, count));
+            if (c == ',' || c == ']') {
+                Integer line = Integer.valueOf(lines.substring(start, i));
+                lineCounts.add(line);
                 start = i + 1;
             } else if (c == ' ') {
                 start = i + 1;
@@ -505,8 +496,8 @@
 
                         fullNames.put(base, file);
 
-                        assert lines.startsWith("{");
-                        assert lines.endsWith("}");
+                        assert lines.startsWith("[");
+                        assert lines.endsWith("]");
 
                         hitCounts.put(file, lines);
                     } catch (IOException ex) {
@@ -584,38 +575,6 @@
         return mimeTypes;
     }
 
-    private static class LineCount {
-        private final int lineno;
-        private int count;
-
-        public LineCount(int lineno, int count) {
-            this.lineno = lineno;
-            this.count = count;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            final LineCount other = (LineCount) obj;
-            if (this.lineno != other.lineno) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public int hashCode() {
-            int hash = 7;
-            hash = 59 * hash + this.lineno;
-            return hash;
-        }
-    }
-
     private static class PythonFileCoverageDetails implements 
FileCoverageDetails {
         private int[] hitCounts;
 

[[nbpython-commits]] [hg] main/contrib: More efficient storage of covered lines for p...

Tor Norbye 10/21/2010

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close