<commit_before>/**
 * evdevkeyboard.h - evdevkeyboard keyboard specialization.
 **/
#pragma once

#include <unordered_map>

#include <thread>

#include "inputmanager.h"

#include "keyboard.h"

#include "evdevice.h"

class EVKeyboard : public Keyboard {
public:
  EVKeyboard(const evdevice & dev) : Keyboard(), device(dev) {
    setupMapping();
  }

  ~EVKeyboard() {

  }

  void setupMapping() {
    evKC.insert({KEY_ESC, KC_Escape});
  }

  static void print_event(const struct input_event & event) {
    std::cout << "Event: " << event.type << " "
              << libevdev_event_type_get_name(event.type)
              << " code: " << event.code << " "
              << libevdev_event_code_get_name(event.type, event.code)
              << std::endl;
  }

  void handleEvents() override {
    struct input_event event;

    if (device.dev == nullptr) {
      std::cout << "Uninitialized device." << std::endl;

      return;
    }

    int rc = libevdev_next_event(device.dev, LIBEVDEV_READ_FLAG_NORMAL, &event);

    if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
      print_event(event);

      if (event.type == EV_KEY) {
        auto iter = evKC.find(event.code);

        if (iter != evKC.end()) {
          toggleKey(iter->second);
        }
      }
    }
  }

private:
  const evdevice device;

  std::unordered_map<int,KeyConstant> evKC;
};
<commit_msg>Increase input performance<commit_after>/**
 * evdevkeyboard.h - evdevkeyboard keyboard specialization.
 **/
#pragma once

#include <unordered_map>

#include <thread>

#include "inputmanager.h"

#include "keyboard.h"

#include "evdevice.h"

class EVKeyboard : public Keyboard {
public:
  EVKeyboard(const evdevice & dev) : Keyboard(), device(dev) {
    setupMapping();
  }

  ~EVKeyboard() {

  }

  void setupMapping() {
    evKC.insert({KEY_ESC, KC_Escape});
  }

  static void print_event(const struct input_event & event) {
    std::cout << "Event: " << event.type << " "
              << libevdev_event_type_get_name(event.type)
              << " code: " << event.code << " "
              << libevdev_event_code_get_name(event.type, event.code)
              << std::endl;
  }

  void handleEvents() override {
    struct input_event event;

    if (device.dev == nullptr) {
      std::cout << "Uninitialized device." << std::endl;

      return;
    }

    int rc = libevdev_next_event(device.dev, LIBEVDEV_READ_FLAG_NORMAL
        | LIBEVDEV_READ_FLAG_BLOCKING, &event);

    if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
      print_event(event);

      if (event.type == EV_KEY) {
        auto iter = evKC.find(event.code);

        if (iter != evKC.end()) {
          toggleKey(iter->second);
        }
      }
    }
  }

private:
  const evdevice device;

  std::unordered_map<int,KeyConstant> evKC;
};

{'fraction_non_alphanumeric': 0.13883880274071403, 'fraction_numerical': 0.0, 'mean_word_length': 2.7741496598639457, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446695', 'n_tokens_mistral': 965, 'n_tokens_neox': 932, 'n_words': 177}