diff options
| author | bors <bors@rust-lang.org> | 2017-08-30 11:08:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-30 11:08:26 +0000 |
| commit | ca9cf3594ab25d2809ac576dfc9defb8e87b45b8 (patch) | |
| tree | c9445d8732ffdea1b395e9e2c0da993574db2e0a /src/libsyntax/tokenstream.rs | |
| parent | c66e7fa8dee0b6b2b5439e2bd527ab66c9fbde13 (diff) | |
| parent | a0c32641fd8bff11b657bfb87d9ade5487d336ae (diff) | |
| download | rust-ca9cf3594ab25d2809ac576dfc9defb8e87b45b8.tar.gz rust-ca9cf3594ab25d2809ac576dfc9defb8e87b45b8.zip | |
Auto merge of #43968 - petrochenkov:span2, r=michaelwoerister
Make fields of `Span` private I actually tried to intern spans and benchmark the result<sup>*</sup>, and this was a prerequisite. This kind of encapsulation will be a prerequisite for any other attempt to compress span's representation, so I decided to submit this change alone. The issue https://github.com/rust-lang/rust/issues/43088 seems relevant, but it looks like `SpanId` won't be able to reuse this interface, unless the tables are global (like interner that I tried) and are not a part of HIR. r? @michaelwoerister anyway <sup>*</sup> Interning means 2-3 times more space is required for a single span, but duplicates are free. In practice it turned out that duplicates are not *that* common, so more memory was wasted by interning rather than saved.
Diffstat (limited to 'src/libsyntax/tokenstream.rs')
| -rw-r--r-- | src/libsyntax/tokenstream.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 747bc7b4385..870f54e4396 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -59,7 +59,7 @@ impl Delimited { let open_span = if span == DUMMY_SP { DUMMY_SP } else { - Span { hi: span.lo + BytePos(self.delim.len() as u32), ..span } + span.with_hi(span.lo() + BytePos(self.delim.len() as u32)) }; TokenTree::Token(open_span, self.open_token()) } @@ -69,7 +69,7 @@ impl Delimited { let close_span = if span == DUMMY_SP { DUMMY_SP } else { - Span { lo: span.hi - BytePos(self.delim.len() as u32), ..span } + span.with_lo(span.hi() - BytePos(self.delim.len() as u32)) }; TokenTree::Token(close_span, self.close_token()) } @@ -602,11 +602,7 @@ mod tests { } fn sp(a: u32, b: u32) -> Span { - Span { - lo: BytePos(a), - hi: BytePos(b), - ctxt: NO_EXPANSION, - } + Span::new(BytePos(a), BytePos(b), NO_EXPANSION) } #[test] |
