Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Fix a performance issue with decoding base16 encoded string #207

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion EosioSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Pod::Spec.new do |s|

s.source = { :git => 'https://github.com/EOSIO/eosio-swift.git', :tag => "v" + s.version.to_s }

s.swift_version = '4.2'
s.swift_version = '5.0'
s.ios.deployment_target = '11.0'

s.source_files = 'EosioSwift/**/*.swift'
Expand All @@ -36,4 +36,5 @@ Pod::Spec.new do |s|

s.ios.dependency 'BigInt', '~> 3.1'
s.ios.dependency 'PromiseKit', '~> 6.8'
s.ios.dependency 'Base16'
end
14 changes: 3 additions & 11 deletions EosioSwift/Extensions/DataExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import CommonCrypto
import Base16

public extension Data {

Expand Down Expand Up @@ -57,17 +58,8 @@ public extension Data {
///
/// - Parameter hexString: A Base16 encoded string.
init?(hexString: String) {
let len = hexString.count / 2
var data = Data(capacity: len)
for i in 0..<len {
let j = hexString.index(hexString.startIndex, offsetBy: i*2) // swiftlint:disable:this identifier_name
let k = hexString.index(j, offsetBy: 2) // swiftlint:disable:this identifier_name
let bytes = hexString[j..<k]
if var num = UInt8(bytes, radix: 16) {
data.append(&num, count: 1)
} else {
return nil
}
guard let data = try? Base16.decode(hexString) else {
return nil
}
self = data
}
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ target 'EosioSwift' do
pod 'BigInt', '~> 3.1', :inhibit_warnings => true
pod 'SwiftLint'
pod 'PromiseKit', '~> 6.8'
pod 'Base16'
end
6 changes: 5 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PODS:
- Base16 (0.1.0)
- BigInt (3.1.0):
- SipHash (~> 1.2)
- OHHTTPStubs/Core (8.0.0)
Expand Down Expand Up @@ -27,26 +28,29 @@ PODS:
- SwiftLint (0.32.0)

DEPENDENCIES:
- Base16
- BigInt (~> 3.1)
- OHHTTPStubs/Swift
- PromiseKit (~> 6.8)
- SwiftLint

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Base16
- BigInt
- OHHTTPStubs
- PromiseKit
- SipHash
- SwiftLint

SPEC CHECKSUMS:
Base16: cf36a62b7936f7bd0b80e84299e41e4098c66457
BigInt: 76b5dfdfa3e2e478d4ffdf161aeede5502e2742f
OHHTTPStubs: 9cbce6364bec557cc3439aa6bb7514670d780881
PromiseKit: 51794a832647e7b819336dc2279039ce9f1cc49b
SipHash: fad90a4683e420c52ef28063063dbbce248ea6d4
SwiftLint: 009a898ef2a1c851f45e1b59349bf6ff2ddc990d

PODFILE CHECKSUM: 1d10bec70f8d2560be35e67e47b034772bba25f7
PODFILE CHECKSUM: a4243c338086085c3dd9dc5842406963c397c4ee

COCOAPODS: 1.7.5