Skip to content

Commit ca32120

Browse files
committed
Use insert() which skips some of the checks
as `__setitem__` also checks if index is a number or slice and then checks the range of the slice; we can skip those knowing that `i1 == i2` in the `insert` opcode.
1 parent 7e0627e commit ca32120

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

jupyter_ydoc/yunicode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, ydoc: Doc | None = None, awareness: Awareness | None = None):
3939
:type awareness: :class:`pycrdt.Awareness`, optional.
4040
"""
4141
super().__init__(ydoc, awareness)
42-
self._ysource = self._ydoc.get("source", type=Text)
42+
self._ysource: Text = self._ydoc.get("source", type=Text)
4343
self.undo_manager.expand_scope(self._ysource)
4444

4545
@property
@@ -91,7 +91,7 @@ def set(self, value: str) -> None:
9191
del self._ysource[i1 + offset : i2 + offset]
9292
offset -= i2 - i1
9393
elif tag == "insert":
94-
self._ysource[i1 + offset : i2 + offset] = value[j1:j2]
94+
self._ysource.insert(i1 + offset, value[j1:j2])
9595
offset += j2 - j1
9696
elif tag == "equal":
9797
pass

0 commit comments

Comments
 (0)