Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Fnv hasher with default capacity #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ serde_json = "1.0.13"
failure = "0.1.1"
serde = "1.0.53"
serde_derive = "1.0.53"
fnv = "1.0.6"

[dependencies.pyo3]
version = "0.4.0"
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ extern crate serde_derive;
extern crate pyo3;
extern crate serde_json;

use std::collections::BTreeMap;
extern crate fnv;

use fnv::FnvHashMap;
use std::fmt;
use std::marker::PhantomData;

use pyo3::prelude::*;
use serde::de::{self, DeserializeSeed, Deserializer, MapAccess, SeqAccess, Visitor};
use serde::ser::{self, Serialize, SerializeMap, SerializeSeq, Serializer};

const DEFAULT_HASHMAP_CAPACITY: usize = 10;

#[derive(Debug, Fail)]
pub enum HyperJsonError {
#[fail(display = "Conversion error: {}", error)]
Expand Down Expand Up @@ -538,7 +542,7 @@ impl<'de, 'a> Visitor<'de> for HyperJsonValue<'a> {
where
A: MapAccess<'de>,
{
let mut entries = BTreeMap::new();
let mut entries = FnvHashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_CAPACITY, Default::default());

while let Some((key, value)) = map.next_entry_seed(PhantomData::<String>, self)? {
entries.insert(key, value);
Expand Down