Skip to content

Commit

Permalink
[mendoza] Handle overlapping prefix/suffix in string rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr authored and rexxars committed Oct 6, 2020
1 parent 82c53c4 commit 68b1108
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/mendoza/src/incremental-patcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export function rebaseValue<T>(left: Value<T>, right: Value<T>): Value<T> {

let result = rightModel.copyString(null)
let prefix = commonPrefix(leftRaw, rightRaw)
let suffix = commonSuffix(leftRaw, rightRaw)
let suffix = commonSuffix(leftRaw, rightRaw, prefix)

let rightLen = utf8stringSize(rightRaw)
let leftLen = utf8stringSize(leftRaw)
Expand Down
4 changes: 2 additions & 2 deletions packages/mendoza/src/utf8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function commonPrefix(str: string, str2: string) {
return b
}

export function commonSuffix(str: string, str2: string) {
let len = Math.min(str.length, str2.length)
export function commonSuffix(str: string, str2: string, prefix: number = 0) {
let len = Math.min(str.length, str2.length) - prefix
let b = 0
for (let i = 0; i < len; ) {
let aPoint = str.codePointAt(str.length - 1 - i)!
Expand Down

0 comments on commit 68b1108

Please sign in to comment.