Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2018-04-30 09:30:22 -0400
committerMickael Istria2018-04-30 09:30:22 -0400
commit162bca1da5a0d6a154a7a58aae5810f564f13fbf (patch)
tree0cd8149829e8e291afb7f82a7e0ab8ffde3706c7 /org.eclipse.text
parentcc244ba39902c89fe397d5f4369288a38c370910 (diff)
downloadeclipse.platform.text-162bca1da5a0d6a154a7a58aae5810f564f13fbf.tar.gz
eclipse.platform.text-162bca1da5a0d6a154a7a58aae5810f564f13fbf.tar.xz
eclipse.platform.text-162bca1da5a0d6a154a7a58aae5810f564f13fbf.zip
Improve some constructs for performance
Issues reported by SonarQube: * iterating on keySet() instead of entrySet() or values() * String += in a loop Change-Id: I3dec0e683305ab3382605168c0505d5ce2bcc35e Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.text')
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java8
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java5
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java6
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java9
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java6
5 files changed, 17 insertions, 17 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
index 736dc58b8..96e609888 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
@@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.runtime.Assert;
@@ -340,10 +341,9 @@ public class TextUtilities {
public static void addDocumentPartitioners(IDocument document, Map<String, ? extends IDocumentPartitioner> partitioners) {
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
- Iterator<String> e= partitioners.keySet().iterator();
- while (e.hasNext()) {
- String partitioning= e.next();
- IDocumentPartitioner partitioner= partitioners.get(partitioning);
+ for (Entry<String, ? extends IDocumentPartitioner> entry : partitioners.entrySet()) {
+ String partitioning= entry.getKey();
+ IDocumentPartitioner partitioner= entry.getValue();
partitioner.connect(document);
extension3.setDocumentPartitioner(partitioning, partitioner);
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java
index 5c3d4d1a3..15c6980b0 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java
@@ -166,9 +166,8 @@ class LinkedModeManager {
}
private void removeManager() {
- for (Iterator<IDocument> it= fgManagers.keySet().iterator(); it.hasNext();) {
- IDocument doc= it.next();
- if (fgManagers.get(doc) == this)
+ for (Iterator<LinkedModeManager> it= fgManagers.values().iterator(); it.hasNext();) {
+ if (it.next() == this)
it.remove();
}
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java
index cad71b6d0..37c9b028c 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java
@@ -15,6 +15,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.runtime.Assert;
@@ -221,8 +222,9 @@ public class LinkedModeModel {
if (result != null) {
// edit all documents
- for (IDocument doc : result.keySet()) {
- TextEdit edit= result.get(doc);
+ for (Entry<IDocument, TextEdit> entry : result.entrySet()) {
+ IDocument doc = entry.getKey();
+ TextEdit edit= entry.getValue();
Replace replace= new Replace(edit);
// apply the edition, either as post notification replace
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java
index 8b7685b02..bbe3e7b0e 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java
@@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.Assert;
@@ -271,10 +272,10 @@ public class LinkedPositionGroup {
try {
Map<IDocument, TextEdit> result= new HashMap<>();
- for (IDocument d : map.keySet()) {
- TextEdit edit= new MultiTextEdit(0, d.getLength());
- edit.addChildren(map.get(d).toArray(new TextEdit[0]));
- result.put(d, edit);
+ for (Entry<IDocument, List<ReplaceEdit>> edits : map.entrySet()) {
+ TextEdit edit= new MultiTextEdit(0, edits.getKey().getLength());
+ edit.addChildren(edits.getValue().toArray(new TextEdit[edits.getValue().size()]));
+ result.put(edits.getKey(), edit);
}
return result;
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
index efe358799..48fdcbfca 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java
@@ -493,8 +493,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
connected();
}
- for (Object object : fAttachments.keySet()) {
- IAnnotationModel model= fAttachments.get(object);
+ for (IAnnotationModel model : fAttachments.values()) {
model.connect(document);
}
}
@@ -518,8 +517,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens
Assert.isTrue(fDocument == document);
- for (Object object : fAttachments.keySet()) {
- IAnnotationModel model= fAttachments.get(object);
+ for (IAnnotationModel model : fAttachments.values()) {
model.disconnect(document);
}

Back to the top