Avoid double handle-read in File::buffer_updated

Max Brunsfeld created

Change summary

zed/src/editor/buffer.rs |  2 +-
zed/src/worktree.rs      | 13 ++++++-------
2 files changed, 7 insertions(+), 8 deletions(-)

Detailed changes

zed/src/editor/buffer.rs 🔗

@@ -1339,7 +1339,7 @@ impl Buffer {
     #[cfg(not(test))]
     pub fn send_operation(&mut self, operation: Operation, cx: &mut ModelContext<Self>) {
         if let Some(file) = &self.file {
-            file.buffer_updated(cx.handle(), operation, cx.as_mut());
+            file.buffer_updated(self.remote_id, operation, cx.as_mut());
         }
     }
 

zed/src/worktree.rs 🔗

@@ -933,13 +933,7 @@ impl File {
         })
     }
 
-    pub fn buffer_updated(
-        &self,
-        buffer: ModelHandle<Buffer>,
-        operation: Operation,
-        cx: &mut MutableAppContext,
-    ) {
-        let buffer_id = buffer.read(cx).remote_id();
+    pub fn buffer_updated(&self, buffer_id: u64, operation: Operation, cx: &mut MutableAppContext) {
         self.worktree.update(cx, |worktree, cx| {
             if let Some((rpc, remote_id)) = match worktree {
                 Worktree::Local(worktree) => worktree.rpc.clone(),
@@ -1883,6 +1877,11 @@ mod remote {
             }) {
                 log::error!("error applying buffer operations {}", error);
             }
+        } else {
+            log::error!(
+                "invalid buffer {} in update buffer message",
+                message.buffer_id
+            );
         }
         Ok(())
     }