mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Substantially improve Scrubber performance.
Previously, we were making a new copy of the entire source string after every scrubbed substitution. In the case of our new, larger log files, this was very slow. It's been changed so we only ever create one new copy. In practice, on a Moto E (2014), scrubbing a 1.5MB log went from >4000ms to ~100ms.
This commit is contained in:
parent
7370bbacea
commit
88d94cad92
@ -46,18 +46,23 @@ public class Scrubber {
|
||||
Log.d(TAG, "scrubbing input");
|
||||
String out = in;
|
||||
for (Pattern pattern : patterns) {
|
||||
Matcher matcher = pattern.matcher(out);
|
||||
while (matcher.find()) {
|
||||
Matcher matcher = pattern.matcher(out);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int lastEndingPos = 0;
|
||||
|
||||
while (matcher.find()) {
|
||||
builder.append(out.substring(lastEndingPos, matcher.start()));
|
||||
|
||||
StringBuilder builder = new StringBuilder(out.substring(0, matcher.start()));
|
||||
final String censored = matcher.group().substring(0,1) +
|
||||
new String(new char[matcher.group().length()-3]).replace("\0", "*") +
|
||||
matcher.group().substring(matcher.group().length()-2);
|
||||
builder.append(censored);
|
||||
builder.append(out.substring(matcher.end()));
|
||||
|
||||
lastEndingPos = matcher.end();
|
||||
Log.i(TAG, "replacing a match on /" + pattern.toString() + "/ => " + censored);
|
||||
out = builder.toString();
|
||||
}
|
||||
builder.append(out.substring(lastEndingPos));
|
||||
out = builder.toString();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user