-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: use myers's difference alogorithm to improve performance
- Loading branch information
Showing
13 changed files
with
528 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import UIKit | ||
import Sdifft | ||
|
||
// Difference between two strings | ||
let source = "Hallo world" | ||
let target = "typo: Hello World!" | ||
|
||
let font = UIFont.systemFont(ofSize: 20) | ||
let insertAttributes: [NSAttributedString.Key: Any] = [ | ||
.backgroundColor: UIColor.green, | ||
.font: font | ||
] | ||
let deleteAttributes: [NSAttributedString.Key: Any] = [ | ||
.backgroundColor: UIColor.red, | ||
.font: font, | ||
.strikethroughStyle: NSUnderlineStyle.single.rawValue, | ||
.strikethroughColor: UIColor.red, | ||
.baselineOffset: 0 | ||
] | ||
|
||
let sameAttributes: [NSAttributedString.Key: Any] = [ | ||
.foregroundColor: UIColor.black, | ||
.font: font | ||
] | ||
|
||
let attributedString1 = | ||
NSAttributedString( | ||
source: source, target: target, | ||
attributes: DiffAttributes(insert: insertAttributes, delete: deleteAttributes, same: sameAttributes) | ||
) | ||
|
||
// Difference between two lines | ||
let sourceLines = ["I'm coding with Swift"] | ||
let targetLines = ["Today", "I'm coding with Swift", "lol"] | ||
|
||
let attributedString2 = | ||
NSAttributedString( | ||
source: sourceLines, target: targetLines, | ||
attributes: DiffAttributes(insert: insertAttributes, delete: deleteAttributes, same: sameAttributes) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' executeOnSourceChanges='false'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
Sdifft.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
22 changes: 22 additions & 0 deletions
22
...ata/xcbaselines/Sdifft::SdifftTests.xcbaseline/A8E95969-EF02-4FA2-9760-6D628059A4C2.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>classNames</key> | ||
<dict> | ||
<key>DiffTests</key> | ||
<dict> | ||
<key>testTime()</key> | ||
<dict> | ||
<key>com.apple.XCTPerformanceMetric_WallClockTime</key> | ||
<dict> | ||
<key>baselineAverage</key> | ||
<real>0.36825</real> | ||
<key>baselineIntegrationDisplayName</key> | ||
<string>Local Baseline</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
22 changes: 22 additions & 0 deletions
22
...ata/xcbaselines/Sdifft::SdifftTests.xcbaseline/DCB9F5A5-E22D-4494-A0DC-4412307D88CA.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>classNames</key> | ||
<dict> | ||
<key>DiffTests</key> | ||
<dict> | ||
<key>testTime()</key> | ||
<dict> | ||
<key>com.apple.XCTPerformanceMetric_WallClockTime</key> | ||
<dict> | ||
<key>baselineAverage</key> | ||
<real>0.8</real> | ||
<key>baselineIntegrationDisplayName</key> | ||
<string>Local Baseline</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
71 changes: 71 additions & 0 deletions
71
Sdifft.xcodeproj/xcshareddata/xcbaselines/Sdifft::SdifftTests.xcbaseline/Info.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>runDestinationsByUUID</key> | ||
<dict> | ||
<key>A8E95969-EF02-4FA2-9760-6D628059A4C2</key> | ||
<dict> | ||
<key>localComputer</key> | ||
<dict> | ||
<key>busSpeedInMHz</key> | ||
<integer>400</integer> | ||
<key>cpuCount</key> | ||
<integer>1</integer> | ||
<key>cpuKind</key> | ||
<string>Intel Core i5</string> | ||
<key>cpuSpeedInMHz</key> | ||
<integer>2300</integer> | ||
<key>logicalCPUCoresPerPackage</key> | ||
<integer>8</integer> | ||
<key>modelCode</key> | ||
<string>MacBookPro15,2</string> | ||
<key>physicalCPUCoresPerPackage</key> | ||
<integer>4</integer> | ||
<key>platformIdentifier</key> | ||
<string>com.apple.platform.macosx</string> | ||
</dict> | ||
<key>targetArchitecture</key> | ||
<string>x86_64</string> | ||
<key>targetDevice</key> | ||
<dict> | ||
<key>modelCode</key> | ||
<string>iPhone10,6</string> | ||
<key>platformIdentifier</key> | ||
<string>com.apple.platform.iphonesimulator</string> | ||
</dict> | ||
</dict> | ||
<key>DCB9F5A5-E22D-4494-A0DC-4412307D88CA</key> | ||
<dict> | ||
<key>localComputer</key> | ||
<dict> | ||
<key>busSpeedInMHz</key> | ||
<integer>400</integer> | ||
<key>cpuCount</key> | ||
<integer>1</integer> | ||
<key>cpuKind</key> | ||
<string>Intel Core i5</string> | ||
<key>cpuSpeedInMHz</key> | ||
<integer>2300</integer> | ||
<key>logicalCPUCoresPerPackage</key> | ||
<integer>8</integer> | ||
<key>modelCode</key> | ||
<string>MacBookPro15,2</string> | ||
<key>physicalCPUCoresPerPackage</key> | ||
<integer>4</integer> | ||
<key>platformIdentifier</key> | ||
<string>com.apple.platform.macosx</string> | ||
</dict> | ||
<key>targetArchitecture</key> | ||
<string>x86_64</string> | ||
<key>targetDevice</key> | ||
<dict> | ||
<key>modelCode</key> | ||
<string>iPhone11,8</string> | ||
<key>platformIdentifier</key> | ||
<string>com.apple.platform.iphonesimulator</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
Oops, something went wrong.