class Hash

def ffi_yajl(yajl_gen, state)

def ffi_yajl(yajl_gen, state)
  if ( status = FFI_Yajl.yajl_gen_map_open(yajl_gen) ) != 0
    FFI_Yajl::Encoder.raise_error_for_status(status)
  end
  self.each do |key, value|
    # Perf Fix: mutate state hash rather than creating new copy
    state[:processing_key] = true
    key.ffi_yajl(yajl_gen, state)
    state[:processing_key] = false
    value.ffi_yajl(yajl_gen, state)
  end
  if ( status = FFI_Yajl.yajl_gen_map_close(yajl_gen) ) != 0
    FFI_Yajl::Encoder.raise_error_for_status(status)
  end
end

def to_json(*opts, &block)

def to_json(*opts, &block)
  FFI_Yajl::Encoder.encode(self, *opts)
end