Bug 862929 - Find end of ANR trace the correct way; r=blassey
authorJim Chen <nchen@mozilla.com>
Wed, 17 Apr 2013 16:29:00 -0700
changeset 129442 8aab5521a29f9e332480adb6f593b4327424dc0b
parent 129441 a1a2af3cebff48ca2f8275add2a5fbc132d9f6f1
child 129443 128ad38ba5d504b81f524440c2cfabe70355f5bd
push id24574
push userryanvm@gmail.com
push dateMon, 22 Apr 2013 12:30:39 +0000
treeherdermozilla-central@ea3ffdbddc53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs862929
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 862929 - Find end of ANR trace the correct way; r=blassey
mobile/android/base/ANRReporter.java
--- a/mobile/android/base/ANRReporter.java
+++ b/mobile/android/base/ANRReporter.java
@@ -381,42 +381,41 @@ public final class ANRReporter extends B
     //   prevIndex, and the rest of the characters in pattern are matched against the
     //   start of this second block. The method returns value > 0 if the rest of the
     //   characters match, or 0 if they do not.
     private static int getEndPatternIndex(String block, String pattern, int prevIndex) {
         if (pattern == null || block.length() < pattern.length()) {
             // Nothing to do
             return 0;
         }
-        if (prevIndex == 0) {
-            // Did not find pattern in last block; see if entire pattern is inside this block
-            int index = block.indexOf(pattern);
-            if (index >= 0) {
-                // Found pattern; return index at end of the pattern
-                return index + pattern.length();
-            }
-            // Block does not contain the entire pattern, but see if the end of the block
-            // contains the start of pattern. To do that, we see if block ends with the
-            // first 1 character of pattern, the first 2 characters of pattern, first 3,
-            // and so on.
-            for (index = block.length() - 1; index > block.length() - pattern.length(); index--) {
-                // Using index as a start, see if the rest of block contains the start of pattern
-                if (block.charAt(index) == pattern.charAt(0) &&
-                    block.endsWith(pattern.substring(0, block.length() - index))) {
-                    // Found partial match; return -(number of characters matched),
-                    // i.e. -1 for 1 character matched, -2 for 2 characters matched, etc.
-                    return index - block.length();
-                }
-            }
-        } else if (prevIndex < 0) {
+        if (prevIndex < 0) {
             // Last block ended with a partial start; now match start of block to rest of pattern
             if (block.startsWith(pattern.substring(-prevIndex, pattern.length()))) {
                 // Rest of pattern matches; return index at end of pattern
                 return pattern.length() + prevIndex;
             }
+            // Not a match; continue with normal search
+        }
+        // Did not find pattern in last block; see if entire pattern is inside this block
+        int index = block.indexOf(pattern);
+        if (index >= 0) {
+            // Found pattern; return index at end of the pattern
+            return index + pattern.length();
+        }
+        // Block does not contain the entire pattern, but see if the end of the block
+        // contains the start of pattern. To do that, we see if block ends with the
+        // first n-1 characters of pattern, the first n-2 characters of pattern, etc.
+        for (index = block.length() - pattern.length() + 1; index < block.length(); index++) {
+            // Using index as a start, see if the rest of block contains the start of pattern
+            if (block.charAt(index) == pattern.charAt(0) &&
+                block.endsWith(pattern.substring(0, block.length() - index))) {
+                // Found partial match; return -(number of characters matched),
+                // i.e. -1 for 1 character matched, -2 for 2 characters matched, etc.
+                return index - block.length();
+            }
         }
         return 0;
     }
 
     // Copy the content of reader to ping and update checksum;
     // copying stops when endPattern is found in the input stream
     private static int fillPingBlock(OutputStream ping, MessageDigest checksum,
                                      Reader reader, String endPattern)