Skip to content

Commit

Permalink
优化CommonDictionary的加载速度
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Nov 17, 2017
1 parent e50be03 commit 1969ebd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,32 @@ public boolean load(ByteArray byteArray, V[] value)
return true;
}

/**
* 从字节数组加载(发现在MacOS上,此方法比ByteArray更快)
* @param bytes
* @param offset
* @param value
* @return
*/
public boolean load(byte[] bytes, int offset, V[] value)
{
if (bytes == null) return false;
size = ByteUtil.bytesHighFirstToInt(bytes, offset);
offset += 4;
base = new int[size + 65535]; // 多留一些,防止越界
check = new int[size + 65535];
for (int i = 0; i < size; i++)
{
base[i] = ByteUtil.bytesHighFirstToInt(bytes, offset);
offset += 4;
check[i] = ByteUtil.bytesHighFirstToInt(bytes, offset);
offset += 4;
}
v = value;
used = null; // 无用的对象,释放掉
return true;
}

/**
* 载入双数组,但是不提供值,此时本trie相当于一个set
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected boolean loadDat(ByteArray byteArray)
{
return false;
}
return trie.load(byteArray, valueArray);
return trie.load(byteArray.getBytes(), byteArray.getOffset(), valueArray);
}

/**
Expand Down

0 comments on commit 1969ebd

Please sign in to comment.