From 5db586b9115604ccf966595145054e9c6e78d101 Mon Sep 17 00:00:00 2001 From: nicksavers Date: Sun, 3 Aug 2014 21:32:33 +0200 Subject: [PATCH] Improve performance matchingNibbleLength --- ethereumj-core/src/main/java/org/ethereum/trie/Trie.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java b/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java index b533fbba..7510c921 100644 --- a/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java +++ b/ethereumj-core/src/main/java/org/ethereum/trie/Trie.java @@ -400,14 +400,18 @@ public class Trie implements TrieFacade { *******************************/ // Returns the amount of nibbles that match each other from 0 ... - private int matchingNibbleLength(byte[] a, byte[] b) { + public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; - while (Arrays.equals(copyOfRange(a, 0, i+1), copyOfRange(b, 0, i+1)) && i < b.length) { + int length = a.length < b.length ? a.length : b.length; + while (i < length) { + if (a[i] != b[i]) + break; i++; } return i; } + // Created an array of empty elements of requred length private Object[] emptyStringSlice(int l) { Object[] slice = new Object[l]; @@ -418,7 +422,6 @@ public class Trie implements TrieFacade { } public byte[] getRootHash() { - Object root = this.getRoot(); if (root == null || (root instanceof byte[] && ((byte[]) root).length == 0) || (root instanceof String && "".equals((String) root))) {