Thread (10 messages) flat view 10 messages, 3 authors, 2016-06-15

Re: [PATCH JGIT] Method invokes inefficient new String(String) constructor

From: Yann Simon <hidden>
Date: 2016-06-15 22:46:25

2009/3/19 Shawn O. Pearce [off-list ref]:
The line in question, p, is from the packed-refs file and
contains the entire SHA-1 in hex form at the beginning of it.
We've converted that into binary as an ObjectId, it uses 1/4 the
space of the string portion.

The Ref object, its ObjectId, and its name string, are going to be
cached in a Map, probably long-term.  We're better off shedding the
80 bytes of memory used to hold the hex SHA-1 then risk substring()
deciding its "faster" to reuse the char[] then to make a copy of it.
Thany you for the explanation.
I learn something, and my tests confirm it.
The p.substring(...) can keep the entire array of char by only
updating the intern offset value.
new String(p.subtring(...)) make sure that the variable contains only
the final chars.

Yann
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help