<commit_before>#include <net/ethernet.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/resource.h>
#include <sys/time.h>

#include "Engine.h"
#include "PcapSource.h"
#include "regexbench.h"

using namespace regexbench;

MatchResult regexbench::match(Engine &engine,
                              const PcapSource &src) {
  struct rusage begin, end;
  MatchResult result;
  getrusage(RUSAGE_SELF, &begin);
  for (auto packet : src) {
    uint16_t offset = 0;
    uint16_t ether_type =
        ntohs(reinterpret_cast<const ether_header *>(packet.data())->ether_type);
    if (ether_type == ETHERTYPE_VLAN) {
      offset = 4;
      ether_type =
          ntohs(reinterpret_cast<const ether_header *>(packet.data() + offset)->ether_type);
    }
    switch (ether_type) {
    case ETHERTYPE_IP: {
      offset += sizeof(ether_header);
      const ip *ih = reinterpret_cast<const ip *>(packet.data() + offset);
      offset += ih->ip_hl << 2;
      switch (ih->ip_p) {
      case IPPROTO_TCP:
        offset += reinterpret_cast<const tcphdr *>(packet.data() + offset)->th_off << 2;
        break;
      case IPPROTO_UDP:
        offset += sizeof(udphdr);
        break;<commit_msg>Use a reference to avoid copying<commit_after>#include <net/ethernet.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/resource.h>
#include <sys/time.h>

#include "Engine.h"
#include "PcapSource.h"
#include "regexbench.h"

using namespace regexbench;

MatchResult regexbench::match(Engine &engine,
                              const PcapSource &src) {
  struct rusage begin, end;
  MatchResult result;
  getrusage(RUSAGE_SELF, &begin);
  for (const auto &packet : src) {
    uint16_t offset = 0;
    uint16_t ether_type =
        ntohs(reinterpret_cast<const ether_header *>(packet.data())->ether_type);
    if (ether_type == ETHERTYPE_VLAN) {
      offset = 4;
      ether_type =
          ntohs(reinterpret_cast<const ether_header *>(packet.data() + offset)->ether_type);
    }
    switch (ether_type) {
    case ETHERTYPE_IP: {
      offset += sizeof(ether_header);
      const ip *ih = reinterpret_cast<const ip *>(packet.data() + offset);
      offset += ih->ip_hl << 2;
      switch (ih->ip_p) {
      case IPPROTO_TCP:
        offset += reinterpret_cast<const tcphdr *>(packet.data() + offset)->th_off << 2;
        break;
      case IPPROTO_UDP:
        offset += sizeof(udphdr);
        break;
{'fraction_non_alphanumeric': 0.1357976653696498, 'fraction_numerical': 0.007003891050583658, 'mean_word_length': 3.1534733441033924, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, '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': '3655725', 'n_tokens_mistral': 911, 'n_tokens_neox': 886, 'n_words': 191}