erichVK5 / BXL2text

A utility to convert huffman encoded BXL schematic and footprint files to plain text, gEDA PCB (.fp) and gschem (.sym), and KiCad (.lib) formats
GNU General Public License v2.0
22 stars 9 forks source link

simple improve for effeciency and dramatic speed increase #3

Closed wlbaker closed 8 years ago

wlbaker commented 8 years ago

It takes three lines of code to improve the performance dramatically. In SourceBuffer.java, change the declaration "String sb = new String()" in the decode() routine to the declaration:

    StringBuffer sb = new StringBuffer(out_file_length);

Then use the method call "sb.append( (char)node.symbol)" method of StringBuffer insteand of "sb = sb + ((char)node;".symbol & 0xff))".

Lastly, the return line of decode should be changed from "return sb;" to "return sb.toString();".

Most of the time in this routine is spent allocating, copying and freeing new String() objects. Performance probably degrades exponentially with the size of the BXL file. This method removes that bottleneck by using a single pre-allocated string buffer.

erichVK5 commented 8 years ago

Implemented, tested and pushed.

Thank you wlbaker, it's much much faster!!

An excellent example of where using StringBuffer can make a big difference.