@@ -156,7 +156,7 @@ pub fn current_revision<Db: ?Sized + Database>(db: &Db) -> Revision {
156
156
mod persistence {
157
157
use crate :: plumbing:: Ingredient ;
158
158
use crate :: zalsa:: Zalsa ;
159
- use crate :: { Database , Runtime } ;
159
+ use crate :: { Database , IngredientIndex , Runtime } ;
160
160
161
161
use std:: fmt;
162
162
@@ -205,21 +205,14 @@ mod persistence {
205
205
. filter ( |ingredient| ingredient. should_serialize ( zalsa) )
206
206
. collect :: < Vec < _ > > ( ) ;
207
207
208
- ingredients. sort_by ( |a, b| {
209
- // Ensure structs are serialized before tracked functions, as deserializing a
210
- // memo requires its input struct to have been deserialized.
211
- //
212
- // We also further sort by debug name, to maintain a consistent ordering across
213
- // builds.
214
- a. jar_kind ( )
215
- . cmp ( & b. jar_kind ( ) )
216
- . then ( a. debug_name ( ) . cmp ( b. debug_name ( ) ) )
217
- } ) ;
208
+ // Ensure structs are serialized before tracked functions, as deserializing a
209
+ // memo requires its input struct to have been deserialized.
210
+ ingredients. sort_by_key ( |ingredient| ingredient. jar_kind ( ) ) ;
218
211
219
212
let mut map = serializer. serialize_map ( Some ( ingredients. len ( ) ) ) ?;
220
213
for ingredient in ingredients {
221
214
map. serialize_entry (
222
- & ingredient. debug_name ( ) ,
215
+ & ingredient. ingredient_index ( ) . as_u32 ( ) ,
223
216
& SerializeIngredient ( ingredient, zalsa) ,
224
217
) ?;
225
218
}
@@ -332,21 +325,17 @@ mod persistence {
332
325
{
333
326
let DeserializeIngredients ( zalsa) = self ;
334
327
335
- while let Some ( name) = access. next_key :: < & str > ( ) ? {
336
- // TODO: Serialize the ingredient index directly.
337
- let ingredient = zalsa
338
- . ingredients ( )
339
- . find ( |ingredient| ingredient. debug_name ( ) == name)
340
- . unwrap ( ) ;
328
+ while let Some ( index) = access. next_key :: < u32 > ( ) ? {
329
+ let index = IngredientIndex :: new ( index) ;
341
330
342
331
// Remove the ingredient temporarily, to avoid holding an overlapping mutable borrow
343
332
// to the ingredient as well as the database.
344
- let mut ingredient = zalsa. take_ingredient ( ingredient . ingredient_index ( ) ) ;
333
+ let mut ingredient = zalsa. take_ingredient ( index ) ;
345
334
346
335
// Deserialize the ingredient.
347
336
access. next_value_seed ( DeserializeIngredient ( & mut * ingredient, zalsa) ) ?;
348
337
349
- zalsa. replace_ingredient ( ingredient . ingredient_index ( ) , ingredient) ;
338
+ zalsa. replace_ingredient ( index , ingredient) ;
350
339
}
351
340
352
341
Ok ( ( ) )
0 commit comments