<commit_before>//
//  SwiftRegex.swift
//  SwiftRegex
//
//  Created by <NAME> on 26/06/2014.
//  Copyright (c) 2014 <NAME>.
//
//  $Id: //depot/SwiftRegex/SwiftRegex.swift#37 $
//
//  This code is in the public domain from:
//  https://github.com/johnno1962/SwiftRegex
//

import Foundation

infix operator <~ { associativity none precedence 130 }

private var swiftRegexCache = [String: NSRegularExpression]()

internal final class SwiftRegex: NSObject, BooleanType {
    var target:String
    var regex: NSRegularExpression
    
    init(target:String, pattern:String, options:NSRegularExpressionOptions?) {
        self.target = target
        if let regex = swiftRegexCache[pattern] {
            self.regex = regex
        } else {
            do {
                let regex = try NSRegularExpression(pattern: pattern, options:
                    NSRegularExpressionOptions.DotMatchesLineSeparators)
                swiftRegexCache[pattern] = regex
                self.regex = regex
            } catch let error as NSError {
                SwiftRegex.failure("Error in pattern: \(pattern) - \(error)")
                self.regex = NSRegularExpression()
            }
        }
        super.init()
    }

    private static func failure(message: String) {<commit_msg>for whatever reason I was able trigger a race condition because of the last commit<commit_after>//
//  SwiftRegex.swift
//  SwiftRegex
//
//  Created by <NAME> on 26/06/2014.
//  Copyright (c) 2014 <NAME>.
//
//  $Id: //depot/SwiftRegex/SwiftRegex.swift#37 $
//
//  This code is in the public domain from:
//  https://github.com/johnno1962/SwiftRegex
//

import Foundation

infix operator <~ { associativity none precedence 130 }

private let lock = dispatch_semaphore_create(1)
private var swiftRegexCache = [String: NSRegularExpression]()

internal final class SwiftRegex: NSObject, BooleanType {
    var target:String
    var regex: NSRegularExpression
    
    init(target:String, pattern:String, options:NSRegularExpressionOptions?) {
        if dispatch_semaphore_wait(lock, dispatch_time(DISPATCH_TIME_NOW, Int64(10 * NSEC_PER_MSEC))) != 0 {
            fatalError("This should never happen")
        }
        
        self.target = target
        if let regex = swiftRegexCache[pattern] {
            self.regex = regex
        } else {
            do {
                let regex = try NSRegularExpression(pattern: pattern, options:
                    NSRegularExpressionOptions.DotMatchesLineSeparators)
                swiftRegexCache[pattern] = regex
                self.regex = regex
            } catch let error as NSError {
                SwiftRegex.failure("Error in pattern: \(pattern) - \(error)")
                self.regex = NSRegularExpression()
            }
        }
        dispatch_semaphore_signal(lock)
        super.init()
    }

    private static func failure(message: String) {
{'fraction_non_alphanumeric': 0.09757785467128027, 'fraction_numerical': 0.01660899653979239, 'mean_word_length': 2.300228310502283, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '80914', 'n_tokens_mistral': 863, 'n_tokens_neox': 772, 'n_words': 207}