Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
loiclec committed Oct 19, 2016
1 parent ea49df7 commit dba8625
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 39 deletions.
10 changes: 0 additions & 10 deletions Sources/Apodimark/DataStructures/Scanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ extension Scanner {
}
}

extension Scanner {

/// Returns a new scanner equal to `self` except `endIndex` is equal to `end`.
/// - precondition: `startIndex <= end && end <= endIndex`
/// - parameter end: the `endIndex` of the new `Scanner`
func prefix(upTo end: Data.Index) -> Scanner {
precondition(startIndex <= end && end <= endIndex)
return Scanner(data: data, startIndex: startIndex, endIndex: end)
}
}
extension Scanner where Data.Iterator.Element: Equatable {

/// Pop elements from the scanner until reaching an element equal to `x`.
Expand Down
13 changes: 0 additions & 13 deletions Sources/Apodimark/DataStructures/Tree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ struct DepthLevel {
func decremented() -> DepthLevel {
return .init(_level-1)
}

static func == (lhs: DepthLevel, rhs: DepthLevel) -> Bool {
return lhs._level == rhs._level
}
}

struct TreeNode <T> {
Expand All @@ -45,11 +41,6 @@ final class Tree <T> {
}

func append(_ data: T, depthLevel level: DepthLevel = .init(0)) {
// if level is 0, then lastStrand is empty
guard level._level <= lastStrand.count else {
fatalError()
}

// update lastStrand
lastStrand.removeSubrange(level._level ..< lastStrand.endIndex)
lastStrand.append(buffer.endIndex)
Expand All @@ -66,10 +57,6 @@ final class Tree <T> {
func append <C: Collection> (strand: C, depthLevel level: DepthLevel = .init(0)) where
C.Iterator.Element == T
{
guard level._level <= lastStrand.count else {
fatalError()
}

let strandLength: Int = numericCast(strand.count)

// update lastStrand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension MarkdownParser {
case .emph(let kind, let state1, let l1) = openingDel.kind,
case .emph(kind, let state2, let l2) = closingDel.kind
else {
fatalError("This should never happen.")
fatalError()
}

defer {
Expand Down
13 changes: 0 additions & 13 deletions Sources/Apodimark/InlineParsing/InlineNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,3 @@ struct NonTextInlineNode <View: BidirectionalCollection> where
(self.kind, self.start, self.end) = (kind, start, end)
}
}

/*
This is only used to efficiently sort an array of InlineNode. For reasons I can’t understand,
sorting an array an InlineNode with a closure like `nodes.sort { $0.start < $1.start }` is less efficient
than making InlineNode conform to Comparabe and use `nodes.sort()`.
*/
extension NonTextInlineNode: Comparable {
static func < (lhs: NonTextInlineNode, rhs: NonTextInlineNode) -> Bool { return lhs.start < rhs.start }
static func <= (lhs: NonTextInlineNode, rhs: NonTextInlineNode) -> Bool { return lhs.start <= rhs.start }
static func == (lhs: NonTextInlineNode, rhs: NonTextInlineNode) -> Bool { return lhs.start == rhs.start }
static func > (lhs: NonTextInlineNode, rhs: NonTextInlineNode) -> Bool { return lhs.start > rhs.start }
static func >= (lhs: NonTextInlineNode, rhs: NonTextInlineNode) -> Bool { return lhs.start >= rhs.start }
}
6 changes: 5 additions & 1 deletion Sources/Apodimark/InlineParsing/InlineParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// Apodimark
//

extension NonTextInlineNode {
static func < (lhs: NonTextInlineNode, rhs: NonTextInlineNode) -> Bool { return lhs.start < rhs.start }
}

extension MarkdownParser {

func parseInlines(_ text: [Range<View.Index>]) -> Tree<InlineNode<View>> {
Expand All @@ -13,7 +17,7 @@ extension MarkdownParser {
nodes += processAllReferences(&dels[dels.indices])
nodes += processAllEmphases(&dels[dels.indices])

nodes.sort()
nodes.sort(by: <)

let textNodes = processText(dels)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct DelimiterState: OptionSet {
if isLeftFlanking && (!isRightFlanking || next == .punctuation) { state.formUnion(.opening) }

default:
fatalError("trying to create emphasis delimiter with character other than asterisk or underscore")
fatalError()
}

self = state
Expand Down

0 comments on commit dba8625

Please sign in to comment.