Skip to content

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5274,7 +5274,7 @@ dependencies = [
52745274
[[package]]
52755275
name = "stringdex"
52765276
version = "0.0.2"
5277-
source = "git+https://gitlab.com/yotamofek/stringdex?rev=5dc67b8e6ce4f2d1f22c176ba881521167b950b1#5dc67b8e6ce4f2d1f22c176ba881521167b950b1"
5277+
source = "git+https://gitlab.com/yotamofek/stringdex?rev=61a1cda4f942e6a6773e4b969aff7b26903a31f8#61a1cda4f942e6a6773e4b969aff7b26903a31f8"
52785278
dependencies = [
52795279
"stacker",
52805280
]

src/librustdoc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rustdoc-json-types = { path = "../rustdoc-json-types" }
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
2323
smallvec = "1.8.1"
24-
stringdex = { git = "https://gitlab.com/yotamofek/stringdex", rev = "5dc67b8e6ce4f2d1f22c176ba881521167b950b1" }
24+
stringdex = { git = "https://gitlab.com/yotamofek/stringdex", rev = "61a1cda4f942e6a6773e4b969aff7b26903a31f8" }
2525
tempfile = "3"
2626
threadpool = "1.8.1"
2727
tracing = "0.1"

src/librustdoc/html/render/search_index.rs

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ mod serde;
33

44
use std::collections::BTreeSet;
55
use std::collections::hash_map::Entry;
6+
use std::io;
67
use std::path::Path;
8+
use std::string::FromUtf8Error;
79

810
use ::serde::de::{self, Deserializer, Error as _};
911
use ::serde::ser::{SerializeSeq, Serializer};
@@ -95,21 +97,28 @@ impl SerializedSearchIndex {
9597
) -> Result<(), Error> {
9698
let root_path = doc_root.join(format!("search.index/root{resource_suffix}.js"));
9799
let column_path = doc_root.join(format!("search.index/{column_name}/"));
100+
101+
struct Consumer<'col>(&'col mut Vec<String>);
102+
103+
impl<'col> stringdex_internals::Consumer for Consumer<'col> {
104+
type Err = FromUtf8Error;
105+
106+
fn consume(&mut self, _id: u32, cell: &[u8]) -> Result<(), Self::Err> {
107+
self.0.push(String::from_utf8(cell.to_vec())?);
108+
Ok(())
109+
}
110+
}
111+
98112
stringdex_internals::read_data_from_disk_column(
99113
root_path,
100114
column_name.as_bytes(),
101115
column_path.clone(),
102-
&mut |_id, item| {
103-
column.push(String::from_utf8(item.to_vec())?);
104-
Ok(())
105-
},
106-
)
107-
.map_err(
108-
|error: stringdex_internals::ReadDataError<Box<dyn std::error::Error>>| Error {
109-
file: column_path,
110-
error: format!("failed to read column from disk: {error}"),
111-
},
116+
&mut Consumer(column),
112117
)
118+
.map_err(|error| Error {
119+
file: column_path,
120+
error: format!("failed to read column from disk: {error}"),
121+
})
113122
}
114123
fn perform_read_serde(
115124
resource_suffix: &str,
@@ -119,25 +128,35 @@ impl SerializedSearchIndex {
119128
) -> Result<(), Error> {
120129
let root_path = doc_root.join(format!("search.index/root{resource_suffix}.js"));
121130
let column_path = doc_root.join(format!("search.index/{column_name}/"));
131+
132+
struct Consumer<'col, T>(&'col mut Vec<Option<T>>);
133+
134+
impl<'col, T> stringdex_internals::Consumer for Consumer<'col, T>
135+
where
136+
T: for<'de> Deserialize<'de> + 'static,
137+
{
138+
type Err = serde_json::Error;
139+
140+
fn consume(&mut self, _id: u32, cell: &[u8]) -> Result<(), Self::Err> {
141+
if cell.is_empty() {
142+
self.0.push(None);
143+
} else {
144+
self.0.push(Some(serde_json::from_slice(cell)?));
145+
}
146+
Ok(())
147+
}
148+
}
149+
122150
stringdex_internals::read_data_from_disk_column(
123151
root_path,
124152
column_name.as_bytes(),
125153
column_path.clone(),
126-
&mut |_id, item| {
127-
if item.is_empty() {
128-
column.push(None);
129-
} else {
130-
column.push(Some(serde_json::from_slice(item)?));
131-
}
132-
Ok(())
133-
},
134-
)
135-
.map_err(
136-
|error: stringdex_internals::ReadDataError<Box<dyn std::error::Error>>| Error {
137-
file: column_path,
138-
error: format!("failed to read column from disk: {error}"),
139-
},
154+
&mut Consumer(column),
140155
)
156+
.map_err(|error| Error {
157+
file: column_path,
158+
error: format!("failed to read column from disk: {error}"),
159+
})
141160
}
142161
fn perform_read_postings(
143162
resource_suffix: &str,
@@ -147,23 +166,30 @@ impl SerializedSearchIndex {
147166
) -> Result<(), Error> {
148167
let root_path = doc_root.join(format!("search.index/root{resource_suffix}.js"));
149168
let column_path = doc_root.join(format!("search.index/{column_name}/"));
169+
170+
struct Consumer<'col>(&'col mut Vec<Vec<Vec<u32>>>);
171+
172+
impl<'col> stringdex_internals::Consumer for Consumer<'col> {
173+
type Err = io::Error;
174+
175+
fn consume(&mut self, _id: u32, cell: &[u8]) -> Result<(), Self::Err> {
176+
let mut postings = Vec::new();
177+
encode::read_postings_from_string(&mut postings, cell);
178+
self.0.push(postings);
179+
Ok(())
180+
}
181+
}
182+
150183
stringdex_internals::read_data_from_disk_column(
151184
root_path,
152185
column_name.as_bytes(),
153186
column_path.clone(),
154-
&mut |_id, buf| {
155-
let mut postings = Vec::new();
156-
encode::read_postings_from_string(&mut postings, buf);
157-
column.push(postings);
158-
Ok(())
159-
},
160-
)
161-
.map_err(
162-
|error: stringdex_internals::ReadDataError<Box<dyn std::error::Error>>| Error {
163-
file: column_path,
164-
error: format!("failed to read column from disk: {error}"),
165-
},
187+
&mut Consumer(column),
166188
)
189+
.map_err(|error| Error {
190+
file: column_path,
191+
error: format!("failed to read column from disk: {error}"),
192+
})
167193
}
168194

169195
assert_eq!(names.len(), path_data.len());

src/tools/tidy/src/extdeps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ALLOWED_SOURCES: &[&str] = &[
1212
// This is `rust_team_data` used by `site` in src/tools/rustc-perf,
1313
r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
1414
// TMP:
15-
r#""git+https://gitlab.com/yotamofek/stringdex?rev=5dc67b8e6ce4f2d1f22c176ba881521167b950b1#5dc67b8e6ce4f2d1f22c176ba881521167b950b1""#,
15+
r#""git+https://gitlab.com/yotamofek/stringdex?rev=61a1cda4f942e6a6773e4b969aff7b26903a31f8#61a1cda4f942e6a6773e4b969aff7b26903a31f8""#,
1616
];
1717

1818
/// Checks for external package sources. `root` is the path to the directory that contains the

0 commit comments

Comments
 (0)