Skip to content

Commit 7e53f41

Browse files
committed
Add inline attributes to syntax_pos
1 parent fc6b2c5 commit 7e53f41

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

src/libsyntax_pos/hygiene.rs

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub enum MarkKind {
5353
}
5454

5555
impl Mark {
56+
#[inline]
5657
pub fn fresh(parent: Mark) -> Self {
5758
HygieneData::with(|data| {
5859
data.marks.push(MarkData { parent: parent, kind: MarkKind::Legacy, expn_info: None });
@@ -171,6 +172,7 @@ impl HygieneData {
171172
}
172173
}
173174

175+
#[inline]
174176
fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
175177
GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
176178
}
@@ -181,6 +183,7 @@ pub fn clear_markings() {
181183
}
182184

183185
impl SyntaxContext {
186+
#[inline]
184187
pub const fn empty() -> Self {
185188
SyntaxContext(0)
186189
}
@@ -450,6 +453,7 @@ pub struct NameAndSpan {
450453
}
451454

452455
impl NameAndSpan {
456+
#[inline]
453457
pub fn name(&self) -> Symbol {
454458
match self.format {
455459
ExpnFormat::MacroAttribute(s) |
@@ -479,6 +483,7 @@ pub enum CompilerDesugaringKind {
479483
}
480484

481485
impl CompilerDesugaringKind {
486+
#[inline]
482487
pub fn as_symbol(&self) -> Symbol {
483488
use CompilerDesugaringKind::*;
484489
let s = match *self {
@@ -491,18 +496,21 @@ impl CompilerDesugaringKind {
491496
}
492497

493498
impl Encodable for SyntaxContext {
499+
#[inline]
494500
fn encode<E: Encoder>(&self, _: &mut E) -> Result<(), E::Error> {
495501
Ok(()) // FIXME(jseyfried) intercrate hygiene
496502
}
497503
}
498504

499505
impl Decodable for SyntaxContext {
506+
#[inline]
500507
fn decode<D: Decoder>(_: &mut D) -> Result<SyntaxContext, D::Error> {
501508
Ok(SyntaxContext::empty()) // FIXME(jseyfried) intercrate hygiene
502509
}
503510
}
504511

505512
impl Symbol {
513+
#[inline]
506514
pub fn from_ident(ident: Ident) -> Symbol {
507515
HygieneData::with(|data| {
508516
let gensym = ident.name.gensymed();
@@ -511,6 +519,7 @@ impl Symbol {
511519
})
512520
}
513521

522+
#[inline]
514523
pub fn to_ident(self) -> Ident {
515524
HygieneData::with(|data| {
516525
match data.gensym_to_ctxt.get(&self) {

src/libsyntax_pos/lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ impl !Send for Span {}
191191
impl !Sync for Span {}
192192

193193
impl PartialOrd for Span {
194+
#[inline]
194195
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
195196
PartialOrd::partial_cmp(&self.data(), &rhs.data())
196197
}
197198
}
198199
impl Ord for Span {
200+
#[inline]
199201
fn cmp(&self, rhs: &Self) -> Ordering {
200202
Ord::cmp(&self.data(), &rhs.data())
201203
}
@@ -253,11 +255,13 @@ impl Span {
253255
}
254256

255257
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
258+
#[inline]
256259
pub fn substitute_dummy(self, other: Span) -> Span {
257260
if self.source_equal(&DUMMY_SP) { other } else { self }
258261
}
259262

260263
/// Return true if `self` fully encloses `other`.
264+
#[inline]
261265
pub fn contains(self, other: Span) -> bool {
262266
let span = self.data();
263267
let other = other.data();
@@ -268,13 +272,15 @@ impl Span {
268272
///
269273
/// Use this instead of `==` when either span could be generated code,
270274
/// and you only care that they point to the same bytes of source text.
275+
#[inline]
271276
pub fn source_equal(&self, other: &Span) -> bool {
272277
let span = self.data();
273278
let other = other.data();
274279
span.lo == other.lo && span.hi == other.hi
275280
}
276281

277282
/// Returns `Some(span)`, where the start is trimmed by the end of `other`
283+
#[inline]
278284
pub fn trim_start(self, other: Span) -> Option<Span> {
279285
let span = self.data();
280286
let other = other.data();
@@ -406,6 +412,7 @@ impl Span {
406412
}
407413

408414
/// Return a `Span` between the end of `self` to the beginning of `end`.
415+
#[inline]
409416
pub fn between(self, end: Span) -> Span {
410417
let span = self.data();
411418
let end = end.data();
@@ -417,6 +424,7 @@ impl Span {
417424
}
418425

419426
/// Return a `Span` between the beginning of `self` to the beginning of `end`.
427+
#[inline]
420428
pub fn until(self, end: Span) -> Span {
421429
let span = self.data();
422430
let end = end.data();
@@ -488,6 +496,7 @@ pub struct SpanLabel {
488496
}
489497

490498
impl Default for Span {
499+
#[inline]
491500
fn default() -> Self {
492501
DUMMY_SP
493502
}
@@ -539,37 +548,43 @@ impl fmt::Debug for SpanData {
539548
}
540549

541550
impl MultiSpan {
551+
#[inline]
542552
pub fn new() -> MultiSpan {
543553
MultiSpan {
544554
primary_spans: vec![],
545555
span_labels: vec![]
546556
}
547557
}
548558

559+
#[inline]
549560
pub fn from_span(primary_span: Span) -> MultiSpan {
550561
MultiSpan {
551562
primary_spans: vec![primary_span],
552563
span_labels: vec![]
553564
}
554565
}
555566

567+
#[inline]
556568
pub fn from_spans(vec: Vec<Span>) -> MultiSpan {
557569
MultiSpan {
558570
primary_spans: vec,
559571
span_labels: vec![]
560572
}
561573
}
562574

575+
#[inline]
563576
pub fn push_span_label(&mut self, span: Span, label: String) {
564577
self.span_labels.push((span, label));
565578
}
566579

567580
/// Selects the first primary span (if any)
581+
#[inline]
568582
pub fn primary_span(&self) -> Option<Span> {
569583
self.primary_spans.first().cloned()
570584
}
571585

572586
/// Returns all primary spans.
587+
#[inline]
573588
pub fn primary_spans(&self) -> &[Span] {
574589
&self.primary_spans
575590
}
@@ -625,12 +640,14 @@ impl MultiSpan {
625640
}
626641

627642
impl From<Span> for MultiSpan {
643+
#[inline]
628644
fn from(span: Span) -> MultiSpan {
629645
MultiSpan::from_span(span)
630646
}
631647
}
632648

633649
impl From<Vec<Span>> for MultiSpan {
650+
#[inline]
634651
fn from(spans: Vec<Span>) -> MultiSpan {
635652
MultiSpan::from_spans(spans)
636653
}
@@ -659,6 +676,7 @@ pub enum NonNarrowChar {
659676
}
660677

661678
impl NonNarrowChar {
679+
#[inline]
662680
fn new(pos: BytePos, width: usize) -> Self {
663681
match width {
664682
0 => NonNarrowChar::ZeroWidth(pos),
@@ -669,6 +687,7 @@ impl NonNarrowChar {
669687
}
670688

671689
/// Returns the absolute offset of the character in the CodeMap
690+
#[inline]
672691
pub fn pos(&self) -> BytePos {
673692
match *self {
674693
NonNarrowChar::ZeroWidth(p) |
@@ -678,6 +697,7 @@ impl NonNarrowChar {
678697
}
679698

680699
/// Returns the width of the character, 0 (zero-width) or 2 (wide)
700+
#[inline]
681701
pub fn width(&self) -> usize {
682702
match *self {
683703
NonNarrowChar::ZeroWidth(_) => 0,
@@ -690,6 +710,7 @@ impl NonNarrowChar {
690710
impl Add<BytePos> for NonNarrowChar {
691711
type Output = Self;
692712

713+
#[inline]
693714
fn add(self, rhs: BytePos) -> Self {
694715
match self {
695716
NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos + rhs),
@@ -702,6 +723,7 @@ impl Add<BytePos> for NonNarrowChar {
702723
impl Sub<BytePos> for NonNarrowChar {
703724
type Output = Self;
704725

726+
#[inline]
705727
fn sub(self, rhs: BytePos) -> Self {
706728
match self {
707729
NonNarrowChar::ZeroWidth(pos) => NonNarrowChar::ZeroWidth(pos - rhs),
@@ -962,6 +984,7 @@ impl FileMap {
962984
/// and CodeMap will append a newline when adding a filemap without a newline at the end,
963985
/// so the safe way to call this is with value calculated as
964986
/// filemap.start_pos + newline_offset_relative_to_the_start_of_filemap.
987+
#[inline]
965988
pub fn next_line(&self, pos: BytePos) {
966989
// the new charpos must be > the last one (or it's the first one).
967990
let mut lines = self.lines.borrow_mut();
@@ -1037,6 +1060,7 @@ impl FileMap {
10371060
}
10381061
}
10391062

1063+
#[inline]
10401064
pub fn record_multibyte_char(&self, pos: BytePos, bytes: usize) {
10411065
assert!(bytes >=2 && bytes <= 4);
10421066
let mbc = MultiByteChar {
@@ -1046,6 +1070,7 @@ impl FileMap {
10461070
self.multibyte_chars.borrow_mut().push(mbc);
10471071
}
10481072

1073+
#[inline]
10491074
pub fn record_width(&self, pos: BytePos, ch: char) {
10501075
let width = match ch {
10511076
'\t' =>
@@ -1176,12 +1201,14 @@ impl Sub for BytePos {
11761201
}
11771202

11781203
impl Encodable for BytePos {
1204+
#[inline]
11791205
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
11801206
s.emit_u32(self.0)
11811207
}
11821208
}
11831209

11841210
impl Decodable for BytePos {
1211+
#[inline]
11851212
fn decode<D: Decoder>(d: &mut D) -> Result<BytePos, D::Error> {
11861213
Ok(BytePos(d.read_u32()?))
11871214
}

src/libsyntax_pos/span_encoding.rs

+4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ pub struct Span(u32);
3131

3232
impl Copy for Span {}
3333
impl Clone for Span {
34+
#[inline]
3435
fn clone(&self) -> Span {
3536
*self
3637
}
3738
}
3839
impl PartialEq for Span {
40+
#[inline]
3941
fn eq(&self, other: &Span) -> bool {
4042
let a = self.0;
4143
let b = other.0;
@@ -44,6 +46,7 @@ impl PartialEq for Span {
4446
}
4547
impl Eq for Span {}
4648
impl Hash for Span {
49+
#[inline]
4750
fn hash<H: Hasher>(&self, state: &mut H) {
4851
let a = self.0;
4952
a.hash(state)
@@ -139,6 +142,7 @@ pub struct SpanInterner {
139142
}
140143

141144
impl SpanInterner {
145+
#[inline]
142146
fn intern(&mut self, span_data: &SpanData) -> u32 {
143147
if let Some(index) = self.spans.get(span_data) {
144148
return *index;

0 commit comments

Comments
 (0)