incr.comp.: Precompute small hash for filenames to save some work. · rust-lang/rust@0258c6d (original) (raw)

`@@ -30,7 +30,7 @@ use std::borrow::Cow;

`

30

30

`use std::cell::{Cell, RefCell};

`

31

31

`use std::cmp::{self, Ordering};

`

32

32

`use std::fmt;

`

33

``

`-

use std::hash::Hasher;

`

``

33

`+

use std::hash::{Hasher, Hash};

`

34

34

`use std::ops::{Add, Sub};

`

35

35

`use std::path::PathBuf;

`

36

36

`use std::rc::Rc;

`

`@@ -691,6 +691,8 @@ pub struct FileMap {

`

691

691

`pub multibyte_chars: RefCell<Vec>,

`

692

692

`/// Width of characters that are not narrow in the source code

`

693

693

`pub non_narrow_chars: RefCell<Vec>,

`

``

694

`+

/// A hash of the filename, used for speeding up the incr. comp. hashing.

`

``

695

`+

pub name_hash: u128,

`

694

696

`}

`

695

697

``

696

698

`impl Encodable for FileMap {

`

`@@ -752,6 +754,9 @@ impl Encodable for FileMap {

`

752

754

`})?;

`

753

755

` s.emit_struct_field("non_narrow_chars", 8, |s| {

`

754

756

`(*self.non_narrow_chars.borrow()).encode(s)

`

``

757

`+

})?;

`

``

758

`+

s.emit_struct_field("name_hash", 9, |s| {

`

``

759

`+

self.name_hash.encode(s)

`

755

760

`})

`

756

761

`})

`

757

762

`}

`

`@@ -801,6 +806,8 @@ impl Decodable for FileMap {

`

801

806

` d.read_struct_field("multibyte_chars", 7, |d| Decodable::decode(d))?;

`

802

807

`let non_narrow_chars: Vec =

`

803

808

` d.read_struct_field("non_narrow_chars", 8, |d| Decodable::decode(d))?;

`

``

809

`+

let name_hash: u128 =

`

``

810

`+

d.read_struct_field("name_hash", 9, |d| Decodable::decode(d))?;

`

804

811

`Ok(FileMap {

`

805

812

` name,

`

806

813

` name_was_remapped,

`

`@@ -816,7 +823,8 @@ impl Decodable for FileMap {

`

816

823

`external_src: RefCell::new(ExternalSource::AbsentOk),

`

817

824

`lines: RefCell::new(lines),

`

818

825

`multibyte_chars: RefCell::new(multibyte_chars),

`

819

``

`-

non_narrow_chars: RefCell::new(non_narrow_chars)

`

``

826

`+

non_narrow_chars: RefCell::new(non_narrow_chars),

`

``

827

`+

name_hash,

`

820

828

`})

`

821

829

`})

`

822

830

`}

`

`@@ -836,9 +844,16 @@ impl FileMap {

`

836

844

`start_pos: BytePos) -> FileMap {

`

837

845

`remove_bom(&mut src);

`

838

846

``

839

``

`-

let mut hasher: StableHasher = StableHasher::new();

`

840

``

`-

hasher.write(src.as_bytes());

`

841

``

`-

let src_hash = hasher.finish();

`

``

847

`+

let src_hash = {

`

``

848

`+

let mut hasher: StableHasher = StableHasher::new();

`

``

849

`+

hasher.write(src.as_bytes());

`

``

850

`+

hasher.finish()

`

``

851

`+

};

`

``

852

`+

let name_hash = {

`

``

853

`+

let mut hasher: StableHasher = StableHasher::new();

`

``

854

`+

name.hash(&mut hasher);

`

``

855

`+

hasher.finish()

`

``

856

`+

};

`

842

857

`let end_pos = start_pos.to_usize() + src.len();

`

843

858

``

844

859

`FileMap {

`

`@@ -854,6 +869,7 @@ impl FileMap {

`

854

869

`lines: RefCell::new(Vec::new()),

`

855

870

`multibyte_chars: RefCell::new(Vec::new()),

`

856

871

`non_narrow_chars: RefCell::new(Vec::new()),

`

``

872

`+

name_hash,

`

857

873

`}

`

858

874

`}

`

859

875

``