This repository has been archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
impl Drop for Node
to avoid overflowing the stack.
The implict drop is correct, but recursive. See the doc-comment for details.
- Loading branch information
1 parent
58ccd6f
commit c05dec7
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extern crate kuchiki; | ||
|
||
fn main() { | ||
let mut depth = 2; | ||
// 20 M nodes is a few GB of memory. | ||
while depth <= 20_000_000 { | ||
|
||
let mut node = kuchiki::NodeRef::new_text(""); | ||
for _ in 0..depth { | ||
let parent = kuchiki::NodeRef::new_text(""); | ||
parent.append(node); | ||
node = parent; | ||
} | ||
|
||
println!("Trying to drop {} nodes...", depth); | ||
// Without an explicit `impl Drop for Node`, | ||
// depth = 20_000 causes "thread '<main>' has overflowed its stack" | ||
// on my machine (Linux x86_64). | ||
::std::mem::drop(node); | ||
|
||
depth *= 10; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tiny nitpick. Shouldn't
Instead, at
, beInstead, it
. Looks great otherwise :)