diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2016-03-14 13:21:26 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2016-03-15 11:51:50 +0100 |
commit | 74e0acf70cb85d2c501e7cd5ea58dfd082ab72cd (patch) | |
tree | e1456abeffdcdea7317f0f8f71f1b0662acca0c3 /sonar-duplications | |
parent | 717e75bc7827bc798ad455543e6d81bce7be4b9e (diff) | |
download | sonarqube-74e0acf70cb85d2c501e7cd5ea58dfd082ab72cd.tar.gz sonarqube-74e0acf70cb85d2c501e7cd5ea58dfd082ab72cd.zip |
SONAR-7158 Time limit for calculation of duplications is ineffective
Diffstat (limited to 'sonar-duplications')
4 files changed, 27 insertions, 1 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneIndex.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneIndex.java index e529a600f54..11cdc7e680f 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneIndex.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/CloneIndex.java @@ -52,4 +52,6 @@ public interface CloneIndex { */ Iterator<ResourceBlocks> iterator(); + + int noResources(); } diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java index 0acb4edc0bb..bbfff14680f 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java @@ -54,4 +54,9 @@ public class MemoryCloneIndex implements CloneIndex { throw new UnsupportedOperationException(); } + @Override + public int noResources() { + return byResource.keySet().size(); + } + } diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java index a0e43ffab6f..97a97d792c4 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java @@ -120,7 +120,7 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex { private Block createBlock(int index, String resourceId, @Nullable ByteArray byteHash) { int offset = index * blockInts; ByteArray blockHash; - + if (byteHash == null) { int[] hash = new int[hashInts]; for (int j = 0; j < hashInts; j++) { @@ -371,4 +371,22 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex { } }; + @Override + /** + * Computation is O(N) + */ + public int noResources() { + ensureSorted(); + int count = 0; + String lastResource = null; + + for (int i = 0; i < size; i++) { + String resource = resourceIds[resourceIdsIndex[i]]; + if (resource != null && !resource.equals(lastResource)) { + count++; + lastResource = resource; + } + } + return count; + } } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java index d96f6ebeaf9..09ff7f055cc 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java @@ -54,6 +54,7 @@ public class PackedMemoryCloneIndexTest { index.insert(newBlock("e", 2)); index.insert(newBlock("e", 3)); + assertThat(index.noResources()).isEqualTo(5); assertThat(index.getBySequenceHash(new ByteArray(1L)).size(), is(5)); assertThat(index.getBySequenceHash(new ByteArray(2L)).size(), is(2)); assertThat(index.getBySequenceHash(new ByteArray(3L)).size(), is(1)); |