<commit_before>
import Glibc


public class StatBuffer: CustomStringConvertible {

  var buffer: CStat
  lazy var _statMode = StatMode()

  public init() {
    buffer = Sys.statBuffer()
  }

  public init(buffer: CStat) {
    self.buffer = buffer
  }

  public func stat(path: String) -> Bool {
    return Sys.doStat(path, buffer: &buffer) == 0
  }

  public func lstat(path: String) -> Bool {
    return Sys.lstat(path, buffer: &buffer) == 0
  }

  public var dev: UInt { return buffer.st_dev }

  public var ino: UInt { return buffer.st_ino }

  public var mode: UInt32 { return buffer.st_mode }

  public var nlink: UInt { return buffer.st_nlink }

  public var uid: UInt32 { return buffer.st_uid }

  public var gid: UInt32 { return buffer.st_gid }

  public var rdev: UInt { return buffer.st_rdev }

  public var size: Int { return buffer.st_size }

  public var blksize: Int { return buffer.st_blksize }

  public var blocks: Int { return buffer.st_blocks }

  func tsToTime(ts: CTimespec) -> Time {
    return Time(secondsSinceEpoch: ts.tv_sec, nanoseconds: ts.tv_nsec)
  }

  public var atime: CTimespec { return buffer.st_atim }

  public var atimeAsTime: Time { return tsToTime(buffer.st_atim) }

  public var mtime: CTimespec { return buffer.st_mtim }

  public var mtimeAsTime: Time { return tsToTime(buffer.st_mtim) }

  public var ctime: CTimespec { return buffer.st_ctim }

  public var ctimeAsTime: Time { return tsToTime(buffer.st_ctim) }

  public var isRegularFile: Bool { return (mode & S_IFMT) == S_IFREG }

  public var isDirectory: Bool { return (mode & S_IFMT) == S_IFDIR }

  public var isSymlink: Bool { return (mode & S_IFMT) == S_IFLNK }

  public var statMode: StatMode {
    _statMode.mode = mode
    return _statMode
  }

  public var description: String {
    return "StatBuffer(dev: \(dev), ino: \(ino), mode: \(mode), " +
        "nlink: \(nlink), uid: \(uid), gid: \(gid), rdev: \(rdev), " +
        "size: \(size), blksize: \(blksize), blocks: \(blocks), " +
        "atime: \(atime), mtime: \(mtime), ctime: \(ctime), " +
        "statMode: \(statMode))"
  }

}


public class StatMode: CustomStringConvertible {

  var mode: UInt32

  public init(mode: UInt32 = 0) {
    self.mode = mode
  }

  public var isRegularFile: Bool { return (mode & S_IFMT) == S_IFREG }

  public var isDirectory: Bool { return (mode & S_IFMT) == S_IFDIR }

  public var isSymlink: Bool { return (mode & S_IFMT) == S_IFLNK }

  public var isSocket: Bool { return (mode & S_IFMT) == S_IFSOCK }

  public var isFifo: Bool { return (mode & S_IFMT) == S_IFIFO }

  public var isBlockDevice: Bool { return (mode & S_IFMT) == S_IFBLK }

  public var isCharacterDevice: Bool { return (mode & S_IFMT) == S_IFCHR }
<commit_msg>Turned StatBuffer and StatMode into structs. At least in a simple program it gave a signficant speed boost of above 15%.<commit_after>
import Glibc


public struct StatBuffer: CustomStringConvertible {

  var buffer: CStat

  public init() {
    buffer = Sys.statBuffer()
  }

  public init(buffer: CStat) {
    self.buffer = buffer
  }

  mutating public func stat(path: String) -> Bool {
    return Sys.doStat(path, buffer: &buffer) == 0
  }

  mutating public func lstat(path: String) -> Bool {
    return Sys.lstat(path, buffer: &buffer) == 0
  }

  public var dev: UInt { return buffer.st_dev }

  public var ino: UInt { return buffer.st_ino }

  public var mode: UInt32 { return buffer.st_mode }

  public var nlink: UInt { return buffer.st_nlink }

  public var uid: UInt32 { return buffer.st_uid }

  public var gid: UInt32 { return buffer.st_gid }

  public var rdev: UInt { return buffer.st_rdev }

  public var size: Int { return buffer.st_size }

  public var blksize: Int { return buffer.st_blksize }

  public var blocks: Int { return buffer.st_blocks }

  func tsToTime(ts: CTimespec) -> Time {
    return Time(secondsSinceEpoch: ts.tv_sec, nanoseconds: ts.tv_nsec)
  }

  public var atime: CTimespec { return buffer.st_atim }

  public var atimeAsTime: Time { return tsToTime(buffer.st_atim) }

  public var mtime: CTimespec { return buffer.st_mtim }

  public var mtimeAsTime: Time { return tsToTime(buffer.st_mtim) }

  public var ctime: CTimespec { return buffer.st_ctim }

  public var ctimeAsTime: Time { return tsToTime(buffer.st_ctim) }

  public var isRegularFile: Bool { return (mode & S_IFMT) == S_IFREG }

  public var isDirectory: Bool { return (mode & S_IFMT) == S_IFDIR }

  public var isSymlink: Bool { return (mode & S_IFMT) == S_IFLNK }

  public var statMode: StatMode {
    return StatMode(mode: mode)
  }

  public var description: String {
    return "StatBuffer(dev: \(dev), ino: \(ino), mode: \(mode), " +
        "nlink: \(nlink), uid: \(uid), gid: \(gid), rdev: \(rdev), " +
        "size: \(size), blksize: \(blksize), blocks: \(blocks), " +
        "atime: \(atime), mtime: \(mtime), ctime: \(ctime), " +
        "statMode: \(statMode))"
  }

}


public struct StatMode: CustomStringConvertible {

  var mode: UInt32

  public init(mode: UInt32 = 0) {
    self.mode = mode
  }

  public var isRegularFile: Bool { return (mode & S_IFMT) == S_IFREG }

  public var isDirectory: Bool { return (mode & S_IFMT) == S_IFDIR }

  public var isSymlink: Bool { return (mode & S_IFMT) == S_IFLNK }

  public var isSocket: Bool { return (mode & S_IFMT) == S_IFSOCK }

  public var isFifo: Bool { return (mode & S_IFMT) == S_IFIFO }

  public var isBlockDevice: Bool { return (mode & S_IFMT) == S_IFBLK }

  public var isCharacterDevice: Bool { return (mode & S_IFMT) == S_IFCHR }

{'fraction_non_alphanumeric': 0.1167027417027417, 'fraction_numerical': 0.005050505050505051, 'mean_word_length': 3.3490196078431373, 'pattern_counts': {'":': 0, '<': 3, '<?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': '611027', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1916, 'n_words': 581}