Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit e6a92bf

Browse files
committed
improve documentation
1 parent 6b15f52 commit e6a92bf

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

crates/rome_parser/src/tree_sink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ where
9494
}
9595
}
9696

97-
/// Reusing `NodeCache` between different [LosslessTreeSink]`s saves memory.
97+
/// Reusing `NodeCache` between different [LosslessTreeSink]s saves memory.
9898
/// It allows to structurally share underlying trees.
9999
pub fn with_cache(text: &'a str, trivia: &'a [Trivia], cache: &'a mut NodeCache) -> Self {
100100
Self {

crates/rome_rowan/src/green/node_cache.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ impl<T: IntoRawPointer> GenerationalPointer<T> {
4242
}
4343

4444
fn value(&self) -> &T::Pointee {
45+
// SAFETY: This clears the least significant bit from `data`. This bit
46+
// should have been set to zero in the original pointer due to the
47+
// alignment requirements of the underlying data (this is checked by an
48+
// assertion on debug builds), so this essentially extracts the pointer
49+
// value from the bit field. Said point is safe to dereference at this
50+
// point since we're holding a valid reference to `self` which
51+
// guarantees `Drop` has not been called and the memory associated with
52+
// the pointer has not been released yet.
4553
let data = self.data & !1;
4654
let ptr = data as *const T::Pointee;
4755
unsafe { &*ptr }

crates/rome_rowan/src/tree_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<L: Language, S: SyntaxFactory<Kind = L::Kind>> TreeBuilder<'_, L, S> {
3636
TreeBuilder::default()
3737
}
3838

39-
/// Reusing `NodeCache` between different [TreeBuilder]`s saves memory.
39+
/// Reusing `NodeCache` between different [TreeBuilder]s saves memory.
4040
/// It allows to structurally share underlying trees.
4141
pub fn with_cache(cache: &mut NodeCache) -> TreeBuilder<'_, L, S> {
4242
cache.increment_generation();

0 commit comments

Comments
 (0)