Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2f7873f8
Commit
2f7873f8
authored
Nov 25, 2025
by
Tobias Koppers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use boxes to avoid moving data a lot
parent
0848e314
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
16 deletions
+12
-16
merge_iter.rs
turbopack/crates/turbo-persistence/src/merge_iter.rs
+12
-16
No files found.
turbopack/crates/turbo-persistence/src/merge_iter.rs
View file @
2f7873f8
use
std
::{
cmp
::
Ordering
,
collections
::
BinaryHeap
};
use
std
::{
cmp
::
Ordering
,
collections
::
BinaryHeap
,
mem
::
replace
};
use
anyhow
::
Result
;
use
anyhow
::
Result
;
...
@@ -40,7 +40,7 @@ impl<'l, T: Iterator<Item = Result<LookupEntry<'l>>>> Ord for ActiveIterator<'l,
...
@@ -40,7 +40,7 @@ impl<'l, T: Iterator<Item = Result<LookupEntry<'l>>>> Ord for ActiveIterator<'l,
/// An iterator that merges multiple sorted iterators into a single sorted iterator. Internal it
/// An iterator that merges multiple sorted iterators into a single sorted iterator. Internal it
/// uses an heap of iterators to iterate them in order.
/// uses an heap of iterators to iterate them in order.
pub
struct
MergeIter
<
'l
,
T
:
Iterator
<
Item
=
Result
<
LookupEntry
<
'l
>>>>
{
pub
struct
MergeIter
<
'l
,
T
:
Iterator
<
Item
=
Result
<
LookupEntry
<
'l
>>>>
{
heap
:
BinaryHeap
<
ActiveIterator
<
'l
,
T
>>
,
heap
:
BinaryHeap
<
Box
<
ActiveIterator
<
'l
,
T
>
>>
,
}
}
impl
<
'l
,
T
:
Iterator
<
Item
=
Result
<
LookupEntry
<
'l
>>>>
MergeIter
<
'l
,
T
>
{
impl
<
'l
,
T
:
Iterator
<
Item
=
Result
<
LookupEntry
<
'l
>>>>
MergeIter
<
'l
,
T
>
{
...
@@ -49,7 +49,7 @@ impl<'l, T: Iterator<Item = Result<LookupEntry<'l>>>> MergeIter<'l, T> {
...
@@ -49,7 +49,7 @@ impl<'l, T: Iterator<Item = Result<LookupEntry<'l>>>> MergeIter<'l, T> {
for
(
order
,
mut
iter
)
in
iters
.enumerate
()
{
for
(
order
,
mut
iter
)
in
iters
.enumerate
()
{
if
let
Some
(
entry
)
=
iter
.next
()
{
if
let
Some
(
entry
)
=
iter
.next
()
{
let
entry
=
entry
?
;
let
entry
=
entry
?
;
heap
.push
(
ActiveIterator
{
iter
,
order
,
entry
}
);
heap
.push
(
Box
::
new
(
ActiveIterator
{
iter
,
order
,
entry
})
);
}
}
}
}
Ok
(
Self
{
heap
})
Ok
(
Self
{
heap
})
...
@@ -60,20 +60,16 @@ impl<'l, T: Iterator<Item = Result<LookupEntry<'l>>>> Iterator for MergeIter<'l,
...
@@ -60,20 +60,16 @@ impl<'l, T: Iterator<Item = Result<LookupEntry<'l>>>> Iterator for MergeIter<'l,
type
Item
=
Result
<
LookupEntry
<
'l
>>
;
type
Item
=
Result
<
LookupEntry
<
'l
>>
;
fn
next
(
&
mut
self
)
->
Option
<
Self
::
Item
>
{
fn
next
(
&
mut
self
)
->
Option
<
Self
::
Item
>
{
let
ActiveIterator
{
let
mut
active_iter
=
self
.heap
.pop
()
?
;
mut
iter
,
let
entry
=
match
active_iter
.iter
.next
()
{
order
,
None
=>
active_iter
.entry
,
entry
,
}
=
self
.heap
.pop
()
?
;
match
iter
.next
()
{
None
=>
{}
Some
(
Err
(
e
))
=>
return
Some
(
Err
(
e
)),
Some
(
Err
(
e
))
=>
return
Some
(
Err
(
e
)),
Some
(
Ok
(
next
))
=>
self
.heap
.push
(
ActiveIterator
{
Some
(
Ok
(
next
))
=>
{
iter
,
let
entry
=
replace
(
&
mut
active_iter
.entry
,
next
);
order
,
self
.heap
.push
(
active_iter
);
entry
:
next
,
entry
}),
}
}
};
Some
(
Ok
(
entry
))
Some
(
Ok
(
entry
))
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment