Files
XcodeGen/Sources/ProjectSpec/Yaml.swift
Romuald Cari 06a6616b88 Improving variable expansion runtime (#704)
* Improving variable expansion runtime

The current implementation of variable expansion is O(n x m) with n being the
number of strings in the project spec and m being the number of project variables.

This implementation is now O(n).

Also, this effectively deprecates the support for $legacy_variables in favor of the
${new_variables} making this whole patch possible.

* Adding option to disable variable expansion

* Adding performance test for spec loading

* Updating changelog
2019-11-06 08:33:54 -06:00

24 lines
635 B
Swift

import Foundation
import PathKit
import Yams
public func loadYamlDictionary(path: Path) throws -> [String: Any] {
let string: String = try path.read()
if string == "" {
return [:]
}
let resolver = Resolver.default
.removing(.null) // remove rule so that empty quotes are treated as empty strings
guard let yaml = try Yams.load(yaml: string, resolver) else {
return [:]
}
return yaml as? [String: Any] ?? [:]
}
public func dumpYamlDictionary(_ dictionary: [String: Any], path: Path) throws {
let string: String = try Yams.dump(object: dictionary)
try path.write(string)
}