@@ -80,10 +80,6 @@ const longItemTypes = [
8080const TY_GENERIC = itemTypes . indexOf ( "generic" ) ;
8181const ROOT_PATH = typeof window !== "undefined" ? window . rootPath : "../" ;
8282
83- function hasOwnPropertyRustdoc ( obj , property ) {
84- return Object . prototype . hasOwnProperty . call ( obj , property ) ;
85- }
86-
8783// In the search display, allows to switch between tabs.
8884function printTab ( nb ) {
8985 let iter = 0 ;
@@ -1074,7 +1070,7 @@ function initSearch(rawSearchIndex) {
10741070
10751071 if ( elem &&
10761072 elem . value !== "all crates" &&
1077- hasOwnPropertyRustdoc ( rawSearchIndex , elem . value )
1073+ rawSearchIndex . has ( elem . value )
10781074 ) {
10791075 return elem . value ;
10801076 }
@@ -2524,11 +2520,10 @@ ${item.displayPath}<span class="${type}">${name}</span>\
25242520 }
25252521
25262522 let crates = "" ;
2527- const crates_list = Object . keys ( rawSearchIndex ) ;
2528- if ( crates_list . length > 1 ) {
2523+ if ( rawSearchIndex . size > 1 ) {
25292524 crates = " in <div id=\"crate-search-div\"><select id=\"crate-search\">" +
25302525 "<option value=\"all crates\">all crates</option>" ;
2531- for ( const c of crates_list ) {
2526+ for ( const c of rawSearchIndex . keys ( ) ) {
25322527 crates += `<option value="${ c } " ${ c === filterCrates && "selected" } >${ c } </option>` ;
25332528 }
25342529 crates += "</select></div>" ;
@@ -2945,81 +2940,70 @@ ${item.displayPath}<span class="${type}">${name}</span>\
29452940 // Function type fingerprints are 128-bit bloom filters that are used to
29462941 // estimate the distance between function and query.
29472942 // This loop counts the number of items to allocate a fingerprint for.
2948- for ( const crate in rawSearchIndex ) {
2949- if ( ! hasOwnPropertyRustdoc ( rawSearchIndex , crate ) ) {
2950- continue ;
2951- }
2943+ for ( const crate of rawSearchIndex . values ( ) ) {
29522944 // Each item gets an entry in the fingerprint array, and the crate
29532945 // does, too
2954- id += rawSearchIndex [ crate ] . t . length + 1 ;
2946+ id += crate . t . length + 1 ;
29552947 }
29562948 functionTypeFingerprint = new Uint32Array ( ( id + 1 ) * 4 ) ;
29572949
29582950 // This loop actually generates the search item indexes, including
29592951 // normalized names, type signature objects and fingerprints, and aliases.
29602952 id = 0 ;
2961- for ( const crate in rawSearchIndex ) {
2962- if ( ! hasOwnPropertyRustdoc ( rawSearchIndex , crate ) ) {
2963- continue ;
2964- }
2965-
2966- let crateSize = 0 ;
2967-
2968- /**
2969- * The raw search data for a given crate. `n`, `t`, `d`, `i`, and `f`
2970- * are arrays with the same length. `q`, `a`, and `c` use a sparse
2971- * representation for compactness.
2972- *
2973- * `n[i]` contains the name of an item.
2974- *
2975- * `t[i]` contains the type of that item
2976- * (as a string of characters that represent an offset in `itemTypes`).
2977- *
2978- * `d[i]` contains the description of that item.
2979- *
2980- * `q` contains the full paths of the items. For compactness, it is a set of
2981- * (index, path) pairs used to create a map. If a given index `i` is
2982- * not present, this indicates "same as the last index present".
2983- *
2984- * `i[i]` contains an item's parent, usually a module. For compactness,
2985- * it is a set of indexes into the `p` array.
2986- *
2987- * `f[i]` contains function signatures, or `0` if the item isn't a function.
2988- * Functions are themselves encoded as arrays. The first item is a list of
2989- * types representing the function's inputs, and the second list item is a list
2990- * of types representing the function's output. Tuples are flattened.
2991- * Types are also represented as arrays; the first item is an index into the `p`
2992- * array, while the second is a list of types representing any generic parameters.
2993- *
2994- * b[i] contains an item's impl disambiguator. This is only present if an item
2995- * is defined in an impl block and, the impl block's type has more than one associated
2996- * item with the same name.
2997- *
2998- * `a` defines aliases with an Array of pairs: [name, offset], where `offset`
2999- * points into the n/t/d/q/i/f arrays.
3000- *
3001- * `doc` contains the description of the crate.
3002- *
3003- * `p` is a list of path/type pairs. It is used for parents and function parameters.
3004- *
3005- * `c` is an array of item indices that are deprecated.
3006- *
3007- * @type {{
3008- * doc: string,
3009- * a: Object,
3010- * n: Array<string>,
3011- * t: String,
3012- * d: Array<string>,
3013- * q: Array<[Number, string]>,
3014- * i: Array<Number>,
3015- * f: Array<RawFunctionSearchType>,
3016- * p: Array<Object>,
3017- * b: Array<[Number, String]>,
3018- * c: Array<Number>
3019- * }}
3020- */
3021- const crateCorpus = rawSearchIndex [ crate ] ;
3022-
2953+ /**
2954+ * The raw search data for a given crate. `n`, `t`, `d`, `i`, and `f`
2955+ * are arrays with the same length. `q`, `a`, and `c` use a sparse
2956+ * representation for compactness.
2957+ *
2958+ * `n[i]` contains the name of an item.
2959+ *
2960+ * `t[i]` contains the type of that item
2961+ * (as a string of characters that represent an offset in `itemTypes`).
2962+ *
2963+ * `d[i]` contains the description of that item.
2964+ *
2965+ * `q` contains the full paths of the items. For compactness, it is a set of
2966+ * (index, path) pairs used to create a map. If a given index `i` is
2967+ * not present, this indicates "same as the last index present".
2968+ *
2969+ * `i[i]` contains an item's parent, usually a module. For compactness,
2970+ * it is a set of indexes into the `p` array.
2971+ *
2972+ * `f[i]` contains function signatures, or `0` if the item isn't a function.
2973+ * Functions are themselves encoded as arrays. The first item is a list of
2974+ * types representing the function's inputs, and the second list item is a list
2975+ * of types representing the function's output. Tuples are flattened.
2976+ * Types are also represented as arrays; the first item is an index into the `p`
2977+ * array, while the second is a list of types representing any generic parameters.
2978+ *
2979+ * b[i] contains an item's impl disambiguator. This is only present if an item
2980+ * is defined in an impl block and, the impl block's type has more than one associated
2981+ * item with the same name.
2982+ *
2983+ * `a` defines aliases with an Array of pairs: [name, offset], where `offset`
2984+ * points into the n/t/d/q/i/f arrays.
2985+ *
2986+ * `doc` contains the description of the crate.
2987+ *
2988+ * `p` is a list of path/type pairs. It is used for parents and function parameters.
2989+ *
2990+ * `c` is an array of item indices that are deprecated.
2991+ *
2992+ * @type {{
2993+ * doc: string,
2994+ * a: Object,
2995+ * n: Array<string>,
2996+ * t: String,
2997+ * d: Array<string>,
2998+ * q: Array<[Number, string]>,
2999+ * i: Array<Number>,
3000+ * f: Array<RawFunctionSearchType>,
3001+ * p: Array<Object>,
3002+ * b: Array<[Number, String]>,
3003+ * c: Array<Number>
3004+ * }}
3005+ */
3006+ for ( const [ crate , crateCorpus ] of rawSearchIndex ) {
30233007 searchWords . push ( crate ) ;
30243008 // This object should have exactly the same set of fields as the "row"
30253009 // object defined below. Your JavaScript runtime will thank you.
@@ -3145,14 +3129,13 @@ ${item.displayPath}<span class="${type}">${name}</span>\
31453129 id += 1 ;
31463130 searchIndex . push ( row ) ;
31473131 lastPath = row . path ;
3148- crateSize += 1 ;
31493132 }
31503133
31513134 if ( aliases ) {
31523135 const currentCrateAliases = new Map ( ) ;
31533136 ALIASES . set ( crate , currentCrateAliases ) ;
31543137 for ( const alias_name in aliases ) {
3155- if ( ! hasOwnPropertyRustdoc ( aliases , alias_name ) ) {
3138+ if ( ! Object . prototype . hasOwnProperty . call ( aliases , alias_name ) ) {
31563139 continue ;
31573140 }
31583141
@@ -3168,7 +3151,7 @@ ${item.displayPath}<span class="${type}">${name}</span>\
31683151 }
31693152 }
31703153 }
3171- currentIndex += crateSize ;
3154+ currentIndex += itemTypes . length ;
31723155 }
31733156 return searchWords ;
31743157 }
@@ -3377,7 +3360,7 @@ if (typeof window !== "undefined") {
33773360} else {
33783361 // Running in Node, not a browser. Run initSearch just to produce the
33793362 // exports.
3380- initSearch ( { } ) ;
3363+ initSearch ( new Map ( ) ) ;
33813364}
33823365
33833366
0 commit comments