<commit_before>#include "propertyItem.h"
#include "properties.h"
#include <algorithm>

namespace Tangram {

Properties::Properties() {}

Properties::~Properties() {}

Properties::Properties(std::vector<Item>&& _items) {
    typedef std::vector<Item>::iterator iter_t;

    props.reserve(_items.size());
    props.insert(props.begin(),
                 std::move_iterator<iter_t>(_items.begin()),
                 std::move_iterator<iter_t>(_items.end()));
    _items.clear();
    sort();
}

Properties& Properties::operator=(Properties&& _other) {
    props = std::move(_other.props);
    return *this;
}

void Properties::setSorted(std::vector<Item>&& _items) {
    props = std::move(_items);
}

const Value& Properties::get(const std::string& key) const {
    const static Value NOT_FOUND(none_type{});

    const auto it = std::lower_bound(props.begin(), props.end(), key,
                                     [](const auto& item, const auto& key) {
                                         return keyComparator(item.key, key);
                                     });

    if (it == props.end() || it->key != key) {
        return NOT_FOUND;
    }
    return it->value;
}

void Properties::clear() { props.clear(); }<commit_msg>perf: find_if vs lower_bound<commit_after>#include "propertyItem.h"
#include "properties.h"
#include <algorithm>

namespace Tangram {

Properties::Properties() {}

Properties::~Properties() {}

Properties::Properties(std::vector<Item>&& _items) {
    typedef std::vector<Item>::iterator iter_t;

    props.reserve(_items.size());
    props.insert(props.begin(),
                 std::move_iterator<iter_t>(_items.begin()),
                 std::move_iterator<iter_t>(_items.end()));
    _items.clear();
    sort();
}

Properties& Properties::operator=(Properties&& _other) {
    props = std::move(_other.props);
    return *this;
}

void Properties::setSorted(std::vector<Item>&& _items) {
    props = std::move(_items);
}

const Value& Properties::get(const std::string& key) const {
    const static Value NOT_FOUND(none_type{});

    const auto it = std::find_if(props.begin(), props.end(),
                                 [&](const auto& item) {
                                     return item.key == key;
                                 });
    if (it == props.end()) {
        return NOT_FOUND;
    }

    // auto it = std::lower_bound(props.begin(), props.end(), key,
    //                            [](auto& item, auto& key) {
    //                                return keyComparator(item.key, key);
    //                            });
    // if (it == props.end() || it->key != key) {
    //     return NOT_FOUND;
    // }

    return it->value;
}

void Properties::clear() { props.clear(); }
{'fraction_non_alphanumeric': 0.16301969365426697, 'fraction_numerical': 0.0, 'mean_word_length': 2.373923739237392, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6931891', 'n_tokens_mistral': 804, 'n_tokens_neox': 794, 'n_words': 156}