summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-10-08 13:27:11 +0200
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-10-08 13:27:11 +0200
commit41b8ab9299542e04e624405aff7dba07a992c297 (patch)
treecbeae9016acb826fb60d7457ec16bf701d4c6ddb /src
parent37422ead1c72d95010a8bc1ecc4feb5fe73f2a5a (diff)
downloadfernflower-41b8ab9299542e04e624405aff7dba07a992c297.tar
fernflower-41b8ab9299542e04e624405aff7dba07a992c297.tar.gz
fernflower-41b8ab9299542e04e624405aff7dba07a992c297.tar.lz
fernflower-41b8ab9299542e04e624405aff7dba07a992c297.tar.xz
fernflower-41b8ab9299542e04e624405aff7dba07a992c297.zip
java-decompiler: minor optimization
Diffstat (limited to 'src')
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassWriter.java7
-rw-r--r--src/org/jetbrains/java/decompiler/main/TextBuffer.java14
2 files changed, 16 insertions, 5 deletions
diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
index bdc2afa..2b61dc2 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
@@ -220,7 +220,7 @@ public class ClassWriter {
}
// FIXME: fields don't matter at the moment
- total_offset_lines = buffer.substring(start_class_def).toString().split(lineSeparator, -1).length - 1;
+ total_offset_lines = buffer.count(lineSeparator, start_class_def);
// methods
for (StructMethod mt : cl.getMethods()) {
@@ -812,8 +812,7 @@ public class ClassWriter {
if (root != null && !methodWrapper.decompiledWithErrors) { // check for existence
try {
-
- tracer.incrementCurrentSourceLine(buffer.substring(start_index_method).split(lineSeparator, -1).length - 1);
+ tracer.incrementCurrentSourceLine(buffer.count(lineSeparator, start_index_method));
String code = root.toJava(indent + 1, tracer);
@@ -842,7 +841,7 @@ public class ClassWriter {
// save total lines
// TODO: optimize
- tracer.setCurrentSourceLine(buffer.substring(start_index_method).split(lineSeparator, -1).length - 1);
+ tracer.setCurrentSourceLine(buffer.count(lineSeparator, start_index_method));
return !hideMethod;
}
diff --git a/src/org/jetbrains/java/decompiler/main/TextBuffer.java b/src/org/jetbrains/java/decompiler/main/TextBuffer.java
index 32766ca..7dd3d2f 100644
--- a/src/org/jetbrains/java/decompiler/main/TextBuffer.java
+++ b/src/org/jetbrains/java/decompiler/main/TextBuffer.java
@@ -17,7 +17,10 @@ package org.jetbrains.java.decompiler.main;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
* Allows to connect text with resulting lines
@@ -172,4 +175,13 @@ public class TextBuffer {
}
myStringBuilder.insert(offset, s);
}
+
+ public int count(String substring, int from) {
+ int count = 0, length = substring.length(), p = from;
+ while ((p = myStringBuilder.indexOf(substring, p)) > 0) {
+ ++count;
+ p += length;
+ }
+ return count;
+ }
}