Java escape HTML - string replace slow?

后端 未结 8 577
长情又很酷
长情又很酷 2021-01-22 17:34

I have a Java application that makes heavy use of a large file, to read, process and give through to SolrEmbeddedServer (http://lucene.apache.org/solr/).

One of the func

8条回答
  •  隐瞒了意图╮
    2021-01-22 17:57

    The general algorithm for String.replace is a little complicated, but it shouldn't be that bad. Looking at the code, it is in fact implemented using regex so wont be fast - ick.

    Obviously, you can write much faster code by iterating through character by character. Possibly working out the exact length first.

    You might want to consider how characters outside of[ -~] are handled. You might also want to use a library which has already implemented the functionality.

提交回复
热议问题