LibPDF: Fix quadratic runtime in stream dumping
DeprecatedString::substring() makes a copy of the substring. Instead, use a StringView, which can make substring views in constant time. Reduces time for `pdf --dump-contents image-based-pdf-sample.pdf` to 2.2s (from not completing for 1+ minutes). That file contains a 221 kB jpeg. Find it on the internet here: https://nlsblog.org/wp-content/uploads/2020/06/image-based-pdf-sample.pdf
This commit is contained in:
parent
d18f01d7d7
commit
93b3f12680
Notes:
sideshowbarker
2024-07-17 06:46:15 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/93b3f12680 Pull-request: https://github.com/SerenityOS/serenity/pull/20017 Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 5 additions and 4 deletions
|
@ -145,13 +145,14 @@ DeprecatedString StreamObject::to_deprecated_string(int indent) const
|
|||
}
|
||||
} else {
|
||||
auto string = encode_hex(bytes());
|
||||
while (string.length() > 60) {
|
||||
builder.appendff("{}\n", string.substring(0, 60));
|
||||
StringView view { string };
|
||||
while (view.length() > 60) {
|
||||
builder.appendff("{}\n", view.substring_view(0, 60));
|
||||
append_indent(builder, indent);
|
||||
string = string.substring(60);
|
||||
view = view.substring_view(60);
|
||||
}
|
||||
|
||||
builder.appendff("{}\n", string);
|
||||
builder.appendff("{}\n", view);
|
||||
}
|
||||
|
||||
builder.append("endstream"sv);
|
||||
|
|
Loading…
Add table
Reference in a new issue