What steps will reproduce the problem?
1. Profile an incoming call
2. indexOfHeader takes a large amount of CPU time.
Suggested patch;
- public int indexOfHeader(String hname) {
- if (str.startsWith(hname, index))
- return index;
- String[] target = { '\n' + hname, '\r' + hname };
- SipParser par = new SipParser(str, index);
- // par.goTo(target);
- par.goToIgnoreCase(target);
- if (par.hasMore())
- par.skipChar();
- return par.getPos();
- }
+ public int indexOfHeader(String hname) {
+ Pattern p = Pattern.compile("^" + hname + ": ",
+ Pattern.CASE_INSENSITIVE
+ | Pattern.MULTILINE);
+ Matcher m = p.matcher(str);
+ if (m.find(index))
+ return m.start();
+ return str.length();
+ }
Slightly better performance could be gained by building a single static Pattern
per caller.
Original issue reported on code.google.com by jer...@lakeman.me on 10 Jun 2011 at 4:32
Original issue reported on code.google.com by
jer...@lakeman.me
on 10 Jun 2011 at 4:32