提交 dda78956 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Specify initial capacity for some string builders

上级 ad6dc91e
...@@ -228,7 +228,7 @@ public class Chunk { ...@@ -228,7 +228,7 @@ public class Chunk {
* @return the string * @return the string
*/ */
public String asString() { public String asString() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder(240);
DataUtils.appendMap(buff, "chunk", id); DataUtils.appendMap(buff, "chunk", id);
DataUtils.appendMap(buff, "block", block); DataUtils.appendMap(buff, "block", block);
DataUtils.appendMap(buff, "len", len); DataUtils.appendMap(buff, "len", len);
...@@ -254,17 +254,17 @@ public class Chunk { ...@@ -254,17 +254,17 @@ public class Chunk {
} }
byte[] getFooterBytes() { byte[] getFooterBytes() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder(FOOTER_LENGTH);
DataUtils.appendMap(buff, "chunk", id); DataUtils.appendMap(buff, "chunk", id);
DataUtils.appendMap(buff, "block", block); DataUtils.appendMap(buff, "block", block);
DataUtils.appendMap(buff, "version", version); DataUtils.appendMap(buff, "version", version);
byte[] bytes = buff.toString().getBytes(StandardCharsets.ISO_8859_1); byte[] bytes = buff.toString().getBytes(StandardCharsets.ISO_8859_1);
int checksum = DataUtils.getFletcher32(bytes, 0, bytes.length); int checksum = DataUtils.getFletcher32(bytes, 0, bytes.length);
DataUtils.appendMap(buff, "fletcher", checksum); DataUtils.appendMap(buff, "fletcher", checksum);
while (buff.length() < Chunk.FOOTER_LENGTH - 1) { while (buff.length() < FOOTER_LENGTH - 1) {
buff.append(' '); buff.append(' ');
} }
buff.append("\n"); buff.append('\n');
return buff.toString().getBytes(StandardCharsets.ISO_8859_1); return buff.toString().getBytes(StandardCharsets.ISO_8859_1);
} }
......
...@@ -801,7 +801,7 @@ public final class MVStore { ...@@ -801,7 +801,7 @@ public final class MVStore {
} }
private void writeStoreHeader() { private void writeStoreHeader() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder(112);
if (lastChunk != null) { if (lastChunk != null) {
storeHeader.put("block", lastChunk.block); storeHeader.put("block", lastChunk.block);
storeHeader.put("chunk", lastChunk.id); storeHeader.put("chunk", lastChunk.id);
...@@ -811,7 +811,7 @@ public final class MVStore { ...@@ -811,7 +811,7 @@ public final class MVStore {
byte[] bytes = buff.toString().getBytes(StandardCharsets.ISO_8859_1); byte[] bytes = buff.toString().getBytes(StandardCharsets.ISO_8859_1);
int checksum = DataUtils.getFletcher32(bytes, 0, bytes.length); int checksum = DataUtils.getFletcher32(bytes, 0, bytes.length);
DataUtils.appendMap(buff, "fletcher", checksum); DataUtils.appendMap(buff, "fletcher", checksum);
buff.append("\n"); buff.append('\n');
bytes = buff.toString().getBytes(StandardCharsets.ISO_8859_1); bytes = buff.toString().getBytes(StandardCharsets.ISO_8859_1);
ByteBuffer header = ByteBuffer.allocate(2 * BLOCK_SIZE); ByteBuffer header = ByteBuffer.allocate(2 * BLOCK_SIZE);
header.put(bytes); header.put(bytes);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论