<commit_before>import NIO

extension ByteBuffer {
    func getDouble(at offset: Int) -> Double? {
        guard let int = getInteger(at: offset, endianness: .little, as: UInt64.self) else {
            return nil
        }
        
        return Double(bitPattern: int)
    }

    func getObjectId(at offset: Int) -> ObjectId? {
        guard
            let timestamp = getInteger(at: offset + 0, endianness: .big, as: UInt32.self),
            let random = getInteger(at: offset + 4, endianness: .big, as: UInt64.self)
        else {
            return nil
        }

        return ObjectId(timestamp: timestamp, random: random)
    }
    
    func getByte(at offset: Int) -> UInt8? {
        return self.getInteger(at: offset, endianness: .little, as: UInt8.self)
    }
    
    /// Returns the first index at which `byte` appears, starting from the reader position
    func firstRelativeIndexOf(byte: UInt8, startingAt: Int) -> Int? {
        withUnsafeReadableBytes { buffer -> Int? in
            var i = startingAt
            
            while i < buffer.count {
                if buffer[i] == 0 {
                    return i - startingAt
                }
                
                i += 1
            }<commit_msg>Even faster document parsing due to a missed optimisation in accessing ByteBuffer<commit_after>import NIO

extension ByteBuffer {
    func getDouble(at offset: Int) -> Double? {
        guard let int = getInteger(at: offset, endianness: .little, as: UInt64.self) else {
            return nil
        }
        
        return Double(bitPattern: int)
    }

    func getObjectId(at offset: Int) -> ObjectId? {
        guard
            let timestamp = getInteger(at: offset + 0, endianness: .big, as: UInt32.self),
            let random = getInteger(at: offset + 4, endianness: .big, as: UInt64.self)
        else {
            return nil
        }

        return ObjectId(timestamp: timestamp, random: random)
    }
    
    func getByte(at offset: Int) -> UInt8? {
        return self.getInteger(at: offset, endianness: .little, as: UInt8.self)
    }
    
    /// Returns the first index at which `byte` appears, starting from the reader position
    func firstRelativeIndexOf(byte: UInt8, startingAt: Int) -> Int? {
        withUnsafeReadableBytes { buffer -> Int? in
            var i = startingAt
            let count = buffer.count
            
            while i < count {
                if buffer[i] == 0 {
                    return i - startingAt
                }
                
                i += 1
            }
{'fraction_non_alphanumeric': 0.09073208722741433, 'fraction_numerical': 0.010124610591900311, 'mean_word_length': 1.6872384937238494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3304226', 'n_tokens_mistral': 742, 'n_tokens_neox': 708, 'n_words': 224}