 
 private extension String {
     func writeToBuffer(inout buffer: [UInt8], inout stringMap: [String: [UInt8]]) {
+        // if the string was already decoded, getting from a dictionary is a cheaper operation than getting utf8 view
         if let bytes = stringMap[self] {
             buffer.appendContentsOf(bytes)
             return

    return result
}

private func countCapacityBytes(array: [CoderTreeValue]) -> [UInt8] {
    var stringMap = Dictionary<String, [UInt8]>(minimumCapacity: stringEntriesCount(array))

    return countCapacityBytes(array, stringMap: &stringMap)
}

private func countCapacityBytes(array: [CoderTreeValue], inout stringMap: [String: [UInt8]]) -> [UInt8] {
    var result = [UInt8]()



// MARK: Types

/// Recursive tree enum that represents data being encoded/decoded
internal indirect enum CoderTreeValue {
    case StringValue(String)
    case IntValue(Int)
