chiark / gitweb /
cmd updates: In UpdateHandlerBulk, use a HashMap not a SlotMap
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 31 Mar 2021 17:21:49 +0000 (18:21 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 1 Apr 2021 10:37:38 +0000 (11:37 +0100)
Otherwise if a slot gets reused, this can go wrong.

It is easier to do this than think about whether the separation of
inserts from deletes would be sufficient.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs

index 371f9e804023309a3b7a94ce696989b39460485f..bcffb751c114d52bdabe5991eed6d9ca2467da3f 100644 (file)
@@ -923,7 +923,7 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
 
 #[derive(Debug,Default)]
 struct UpdateHandlerBulk {
-  pieces: slotmap::SparseSecondaryMap<PieceId, PieceUpdateOp<(),()>>,
+  pieces: HashMap<PieceId, PieceUpdateOp<(),()>>,
   logs: bool,
   raw: Vec<PreparedUpdateEntry>,
 }
@@ -952,7 +952,7 @@ impl UpdateHandler {
       Bulk(bulk) => {
         for (upiece, uuop) in updates.pcs {
           use PieceUpdateOp::*;
-          let oe = bulk.pieces.get(upiece);
+          let oe = bulk.pieces.get(&upiece);
           let ne = match (oe, uuop) {
             ( None               , e        ) => Some( e          ),
             ( Some( Insert(()) ) , Delete() ) => None,
@@ -963,7 +963,7 @@ impl UpdateHandler {
           trace_dbg!("accumulate", upiece, oe, uuop, ne);
           match ne {
             Some(ne) => { bulk.pieces.insert(upiece, ne); },
-            None     => { bulk.pieces.remove(upiece);     },
+            None     => { bulk.pieces.remove(&upiece);    },
           };
         }
         bulk.logs |= updates.log.len() != 0;