mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibJS/Bytecode: Merge adjacent exception handlers
For example, this:
```
Exception handlers:
from 678 to 698 handler 658 finalizer 0
from 698 to 6f8 handler 658 finalizer 0
from 6f8 to 708 handler 658 finalizer 0
from 708 to 750 handler 658 finalizer 0
from 750 to 788 handler 658 finalizer 0
from 788 to 7a0 handler 658 finalizer 0
from 7a0 to 7a8 handler 658 finalizer 0
```
Becomes:
```
Exception handlers:
from 678 to 7a8 handler 658 finalizer 0
```
This commit is contained in:
parent
86b95b1d7a
commit
d0ef1aad2d
Notes:
github-actions[bot]
2025-11-07 08:58:11 +00:00
Author: https://github.com/Lubrsi
Commit: d0ef1aad2d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6444
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/konradekk
1 changed files with 11 additions and 1 deletions
|
|
@ -462,7 +462,17 @@ CodeGenerationErrorOr<GC::Ref<Executable>> Generator::compile(VM& vm, ASTNode co
|
|||
auto end_offset = unlinked_handler.end_offset;
|
||||
auto handler_offset = unlinked_handler.handler ? block_offsets.get(unlinked_handler.handler).value() : Optional<size_t> {};
|
||||
auto finalizer_offset = unlinked_handler.finalizer ? block_offsets.get(unlinked_handler.finalizer).value() : Optional<size_t> {};
|
||||
linked_exception_handlers.append({ start_offset, end_offset, handler_offset, finalizer_offset });
|
||||
|
||||
auto maybe_exception_handler_to_merge_with = linked_exception_handlers.find_if([&](Executable::ExceptionHandlers const& exception_handler) {
|
||||
return exception_handler.end_offset == start_offset && exception_handler.handler_offset == handler_offset && exception_handler.finalizer_offset == finalizer_offset;
|
||||
});
|
||||
|
||||
if (!maybe_exception_handler_to_merge_with.is_end()) {
|
||||
auto& exception_handler_to_merge_with = *maybe_exception_handler_to_merge_with;
|
||||
exception_handler_to_merge_with.end_offset = end_offset;
|
||||
} else {
|
||||
linked_exception_handlers.append({ start_offset, end_offset, handler_offset, finalizer_offset });
|
||||
}
|
||||
}
|
||||
|
||||
quick_sort(linked_exception_handlers, [](auto const& a, auto const& b) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue