<div class="__aliyun_email_body_block"><div  style="line-height:1.7;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#0070c0;"><div  style="clear:both;"><span >Using the new method, the performance is improved by approximately 26% when running on MaxBookPro M1 Max.</span></div><div  style="clear:both;"><span ><br ></span></div><div  style="clear:both;">```</div><div  style="clear:both;"><span >Benchmark                         Mode  Cnt   Score   Error  Units</span><div  style="clear:both;">StringBuilders.appendHex8         avgt   15  15.259 ? 0.121  ns/op (+26.19%)</div><span >StringBuilders.appendHexCombine8  avgt   15  19.256 ? 0.059  ns/op</span></div><div  style="clear:both;"><span >```</span></div><div  style="clear:both;"><span ><br ></span></div><div  style="clear:both;"><span >The test code is as follows:</span></div><div  style="clear:both;"><span >```java</span><div  style="clear:both;">public class StringBuilders {</div><div  style="clear:both;">    @Benchmark</div><div  style="clear:both;">    public String appendHexCombine8() {</div><div  style="clear:both;">        StringBuilder result = new StringBuilder();</div><div  style="clear:both;">        result.append(Integer.toHexString(2048));</div><div  style="clear:both;">        result.append(Integer.toHexString(31337));</div><div  style="clear:both;">        result.append(Integer.toHexString(0xbeefcace));</div><div  style="clear:both;">        result.append(Integer.toHexString(9000));</div><div  style="clear:both;">        result.append(Integer.toHexString(4711));</div><div  style="clear:both;">        result.append(Integer.toHexString(1337));</div><div  style="clear:both;">        result.append(Integer.toHexString(2100));</div><div  style="clear:both;">        result.append(Integer.toHexString(2600));</div><div  style="clear:both;">        return result.toString();</div><div  style="clear:both;">    }</div><div  style="clear:both;">    @Benchmark</div><div  style="clear:both;">    public String appendHex8() {</div><div  style="clear:both;">        StringBuilder result = new StringBuilder();</div><div  style="clear:both;">        result.appendHex(2048);</div><div  style="clear:both;">        result.appendHex(31337);</div><div  style="clear:both;">        result.appendHex(0xbeefcace);</div><div  style="clear:both;">        result.appendHex(9000);</div><div  style="clear:both;">        result.appendHex(4711);</div><div  style="clear:both;">        result.appendHex(1337);</div><div  style="clear:both;">        result.appendHex(2100);</div><div  style="clear:both;">        result.appendHex(2600);</div><div  style="clear:both;">        return result.toString();</div><div  style="clear:both;">    }</div><div  style="clear:both;">}</div><span >```</span></div><div  style="clear:both;"><br ></div><div  style="clear:both;"><br ></div><div  style="clear:both;"><br ></div><blockquote  _quote="1" style="margin-right:.0px;margin-top:.0px;margin-bottom:.0px;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><div  style="clear:both;">------------------------------------------------------------------</div><div  style="clear:both;">发件人:Bernd <ecki@zusammenkunft.net></div><div  style="clear:both;">发送时间:2023年10月1日(星期日) 00:50</div><div  style="clear:both;">收件人:温绍锦(高铁) <shaojin.wensj@alibaba-inc.com>; core-libs-dev <core-libs-dev@openjdk.org></div><div  style="clear:both;">主 题:Re: Adding appendHex method to StringBuilder</div><div  style="clear:both;"><br ></div><div ><div >
  
  
  
    </div><div ><div >
        
        <div >Or maybe make it more generic and allow to specify the base as well, that’s more along the line of existing toString() methods of numbers.</div><div ><br ></div><div >besides convinience, I wonder if it would actually improve performance, how good is the JIT and EA in that case, did you run some benchmarks?</div><div ><br ></div><div >Gruss</div><div >Bernd</div><div  id="ms-outlook-mobile-signature"><div  style="direction:ltr;">-- </div><div  style="direction:ltr;"><a  href="http://bernd.eckenfels.net" target="_blank">http://bernd.eckenfels.net</a></div></div>
    </div>
  

<div > </div><hr  style="display:inline-block;width:98.0%;"><div  id="divRplyFwdMsg"><span  style="font-family:Calibri,sans-serif;"><b >Von:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> im Auftrag von 温绍锦(高铁) <shaojin.wensj@alibaba-inc.com><br ><b >Gesendet:</b> Samstag, September 30, 2023 2:07 PM<br ><b >An:</b> core-libs-dev <core-libs-dev@openjdk.org><br ><b >Betreff:</b> Adding appendHex method to StringBuilder<div > </div></span></div><div  class=" __aliyun_node_has_color" style="line-height:1.7;font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#0070c0;"><div  style="clear:both;">There are many combinations of `append(Integer.toHexString(i))` and `append(Long.toHexString(i))` in the JDK code. I request to add method `appendHex(int)` and `appendHex(int)` to StringBuilder and StringBuffer. This can reduce duplicate code within the JDK and will also be useful to users.<br ></div><div  style="line-height:20.0px;clear:both;"><div  style="clear:both;"><br ></div><div  style="clear:both;">I submitted a PR ( <a  href="https://github.com/openjdk/jdk/pull/15998" target="_blank">https://github.com/openjdk/jdk/pull/15998</a> ), including the code and tests for the new method. I also replaced the code that uses the append + toHexString combination inside the JDK with appendHex.</div><span ><div  style="line-height:20.0px;clear:both;"><span ><br ></span></div>Please review and don't hesitate to critique my approach and patch.</span></div></div></div></div></blockquote><div  style="line-height:20.0px;clear:both;"><br ></div></div></div>