MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / frame

Method frame

atomic-core/src/pristine/span_patch_storage.rs:1378–1442  ·  view source on GitHub ↗
(&self, inode: Inode, span: [u64; 3])

Source from the content-addressed store, hash-verified

1376 }
1377
1378 fn frame(&self, inode: Inode, span: [u64; 3]) -> Result<RenderFrame> {
1379 let [owner, start, end] = span;
1380 let owner = NodeId::new(owner);
1381 ensure!(self.visible.contains(owner), "span outside view");
1382 let key = span_key(inode, owner, start, end);
1383 ensure!(self.txn.span_exists(&key)?, "span index row missing");
1384 let hash = self.txn.get_external(owner)?.context("span hash missing")?;
1385 let change = Arc::clone(
1386 self.changes
1387 .get(&hash)
1388 .context("span change outside closure")?,
1389 );
1390 let (start, end) = (usize::try_from(start)?, usize::try_from(end)?);
1391 change
1392 .contents
1393 .get(start..end)
1394 .context("span outside change content")?;
1395 let mut edits: Vec<[u64; 5]> = self
1396 .txn
1397 .span_edits_at(&key)?
1398 .into_iter()
1399 .map(|row| decode_words::<5>(&row))
1400 .filter(|row| self.visible.contains(NodeId::new(row[2])))
1401 .collect();
1402 edits.sort_by_key(|row| (row[0], row[1], row[2]));
1403 let mut group = 0;
1404 while group < edits.len() {
1405 let mut end_group = group + 1;
1406 while end_group < edits.len()
1407 && edits[group][0] == edits[group][1]
1408 && edits[end_group][0] == edits[group][0]
1409 && edits[end_group][1] == edits[group][1]
1410 {
1411 end_group += 1;
1412 }
1413 for i in group..end_group {
1414 for j in i + 1..end_group {
1415 let left = edits[i][2];
1416 let right = edits[j][2];
1417 ensure!(
1418 left != right,
1419 "ambiguous insertions from one change at the same gap"
1420 );
1421 if self.depends_on(right, left)? {
1422 edits.swap(i, j);
1423 } else if !self.depends_on(left, right)? {
1424 bail!("unsupported concurrent insertions at the same gap");
1425 }
1426 }
1427 }
1428 group = end_group;
1429 }
1430 Ok(RenderFrame {
1431 span,
1432 hash,
1433 change,
1434 start,
1435 end,

Callers 1

render_spansMethod · 0.80

Calls 10

span_keyFunction · 0.85
getMethod · 0.65
contextMethod · 0.45
get_externalMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
span_edits_atMethod · 0.45
containsMethod · 0.45
lenMethod · 0.45
depends_onMethod · 0.45

Tested by

no test coverage detected