<commit_before>// swiftlint:disable cyclomatic_complexity function_body_length
import Foundation

extension Formatting {
    init?(from tag: HtmlTag) {
        switch tag {
        case .a: self = .url
        case .b: self = .bold
        case .i: self = .italic
        case .u: self = .underline
        case .p: self = .paragraph
        case .pre: self = .preformatted
        case .code: self = .code
        case .br: self = .linebreak
        }
    }
}

extension String {
    func strippingHtmlElements() -> FormattedString {
        let newline: UnicodeScalar = "\n"

        var result = ""
        var points = [(Formatting, Range<Index>)]()
        var tags = [HtmlTag: [Range<Index>]]()

        func push(_ tag: HtmlTag) {
            let tagRange = result.endIndex..<result.endIndex
            var stack = tags[tag] ?? []
            stack.append(tagRange)
            tags[tag] = stack
        }
<commit_msg>Reserve initial capacity for result string to reduce allocations<commit_after>// swiftlint:disable cyclomatic_complexity function_body_length
import Foundation

extension Formatting {
    init?(from tag: HtmlTag) {
        switch tag {
        case .a: self = .url
        case .b: self = .bold
        case .i: self = .italic
        case .u: self = .underline
        case .p: self = .paragraph
        case .pre: self = .preformatted
        case .code: self = .code
        case .br: self = .linebreak
        }
    }
}

extension String {
    func strippingHtmlElements() -> FormattedString {
        let newline: UnicodeScalar = "\n"

        var result = String()
        result.reserveCapacity(utf8.count)

        var points = [(Formatting, Range<Index>)]()
        var tags = [HtmlTag: [Range<Index>]]()

        func push(_ tag: HtmlTag) {
            let tagRange = result.endIndex..<result.endIndex
            var stack = tags[tag] ?? []
            stack.append(tagRange)
            tags[tag] = stack
        }

{'fraction_non_alphanumeric': 0.11059907834101383, 'fraction_numerical': 0.0005120327700972862, 'mean_word_length': 1.9295352323838082, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5201671', 'n_tokens_mistral': 572, 'n_tokens_neox': 560, 'n_words': 164}