Skip to content

Commit 217fe24

Browse files
committed
rustdoc-search: null, not -1, for missing id
This allows us to use negative numbers for others purposes.
1 parent 2a1af89 commit 217fe24

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/librustdoc/html/static/js/externs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function initSearch(searchIndex){}
99
/**
1010
* @typedef {{
1111
* name: string,
12-
* id: integer,
12+
* id: integer|null,
1313
* fullPath: Array<string>,
1414
* pathWithoutLast: Array<string>,
1515
* pathLast: string,

src/librustdoc/html/static/js/search.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function initSearch(rawSearchIndex) {
252252

253253
/**
254254
* Add an item to the type Name->ID map, or, if one already exists, use it.
255-
* Returns the number. If name is "" or null, return -1 (pure generic).
255+
* Returns the number. If name is "" or null, return null (pure generic).
256256
*
257257
* This is effectively string interning, so that function matching can be
258258
* done more quickly. Two types with the same name but different item kinds
@@ -264,7 +264,7 @@ function initSearch(rawSearchIndex) {
264264
*/
265265
function buildTypeMapIndex(name) {
266266
if (name === "" || name === null) {
267-
return -1;
267+
return null;
268268
}
269269

270270
if (typeNameIdMap.has(name)) {
@@ -489,7 +489,7 @@ function initSearch(rawSearchIndex) {
489489
}
490490
return {
491491
name: "never",
492-
id: -1,
492+
id: null,
493493
fullPath: ["never"],
494494
pathWithoutLast: [],
495495
pathLast: "never",
@@ -531,7 +531,7 @@ function initSearch(rawSearchIndex) {
531531
}
532532
return {
533533
name: name.trim(),
534-
id: -1,
534+
id: null,
535535
fullPath: pathSegments,
536536
pathWithoutLast: pathSegments.slice(0, pathSegments.length - 1),
537537
pathLast: pathSegments[pathSegments.length - 1],
@@ -660,7 +660,7 @@ function initSearch(rawSearchIndex) {
660660
}
661661
elems.push({
662662
name: "[]",
663-
id: -1,
663+
id: null,
664664
fullPath: ["[]"],
665665
pathWithoutLast: [],
666666
pathLast: "[]",
@@ -1172,7 +1172,7 @@ function initSearch(rawSearchIndex) {
11721172
const out = [];
11731173

11741174
for (const result of results) {
1175-
if (result.id > -1) {
1175+
if (result.id !== -1) {
11761176
const obj = searchIndex[result.id];
11771177
obj.dist = result.dist;
11781178
const res = buildHrefAndPath(obj);
@@ -1403,7 +1403,7 @@ function initSearch(rawSearchIndex) {
14031403
// [unboxing]:
14041404
// http://ndmitchell.com/downloads/slides-hoogle_fast_type_searching-09_aug_2008.pdf
14051405
const queryContainsArrayOrSliceElem = queryElemSet.has(typeNameIdOfArrayOrSlice);
1406-
if (fnType.id === -1 || !(
1406+
if (fnType.id === null || !(
14071407
queryElemSet.has(fnType.id) ||
14081408
(fnType.id === typeNameIdOfSlice && queryContainsArrayOrSliceElem) ||
14091409
(fnType.id === typeNameIdOfArray && queryContainsArrayOrSliceElem)
@@ -1564,7 +1564,7 @@ function initSearch(rawSearchIndex) {
15641564
* @return {boolean} - Returns true if the type matches, false otherwise.
15651565
*/
15661566
function checkType(row, elem) {
1567-
if (row.id === -1) {
1567+
if (row.id === null) {
15681568
// This is a pure "generic" search, no need to run other checks.
15691569
return row.generics.length > 0 ? checkIfInList(row.generics, elem) : false;
15701570
}
@@ -1891,7 +1891,7 @@ function initSearch(rawSearchIndex) {
18911891
if (typeNameIdMap.has(elem.pathLast)) {
18921892
elem.id = typeNameIdMap.get(elem.pathLast);
18931893
} else if (!parsedQuery.literalSearch) {
1894-
let match = -1;
1894+
let match = null;
18951895
let matchDist = maxEditDistance + 1;
18961896
let matchName = "";
18971897
for (const [name, id] of typeNameIdMap) {
@@ -1905,7 +1905,7 @@ function initSearch(rawSearchIndex) {
19051905
matchName = name;
19061906
}
19071907
}
1908-
if (match !== -1) {
1908+
if (match !== null) {
19091909
parsedQuery.correction = matchName;
19101910
}
19111911
elem.id = match;
@@ -2413,7 +2413,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
24132413
// `0` is used as a sentinel because it's fewer bytes than `null`
24142414
if (pathIndex === 0) {
24152415
return {
2416-
id: -1,
2416+
id: null,
24172417
ty: null,
24182418
path: null,
24192419
generics: generics,
@@ -2457,7 +2457,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
24572457
const pathIndex = functionSearchType[INPUTS_DATA];
24582458
if (pathIndex === 0) {
24592459
inputs = [{
2460-
id: -1,
2460+
id: null,
24612461
ty: null,
24622462
path: null,
24632463
generics: [],
@@ -2482,7 +2482,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
24822482
const pathIndex = functionSearchType[OUTPUT_DATA];
24832483
if (pathIndex === 0) {
24842484
output = [{
2485-
id: -1,
2485+
id: null,
24862486
ty: null,
24872487
path: null,
24882488
generics: [],

0 commit comments

Comments
 (0)