<commit_before>#include "toll.h"
#include <cstdlib>

namespace oop_project {

const size_t Toll::kMaxCars = 5;

Toll::Toll(size_t current_junction, size_t num_junctions) {
  size_t num_cars = rand() % kMaxCars + 1;
  cars_.resize(num_cars);
  for (size_t i = 0; i < cars_.size(); ++i) {
    size_t exit_junction = rand() % (num_junctions - current_junction) +
                           current_junction;
    cars_[i] = new Car(exit_junction, NULL);
  }
}

Toll::~Toll() {
  for (size_t i = 0; i < cars_.size(); ++i) {
    delete cars_[i];
  }
}

void Toll::Add(Car* car) {
  cars_.push_back(car);
}

std::vector<Car*> Toll::Remove() {
  return Remove(cars_.size());
}

std::vector<Car*> Toll::Remove(size_t num_cars) {
  std::vector<Car*> ret;
  if (cars_.size() > num_cars) {
    ret.insert(ret.begin(), cars_.begin(), cars_.begin() + num_cars);
    cars_.erase(cars_.begin(), cars_.begin() + num_cars);
  } else {
    ret = cars_;
    cars_.clear();
  }
  return ret;
}

size_t Toll::num_cars() const {
  return cars_.size();
}

}  // namespace oop_project<commit_msg>Toll: Vector.insert() optimization<commit_after>#include "toll.h"
#include <cstdlib>

namespace oop_project {

const size_t Toll::kMaxCars = 5;

Toll::Toll(size_t current_junction, size_t num_junctions) {
  size_t num_cars = rand() % kMaxCars + 1;
  cars_.resize(num_cars);
  for (size_t i = 0; i < cars_.size(); ++i) {
    size_t exit_junction = rand() % (num_junctions - current_junction) +
                           current_junction;
    cars_[i] = new Car(exit_junction, NULL);
  }
}

Toll::~Toll() {
  for (size_t i = 0; i < cars_.size(); ++i) {
    delete cars_[i];
  }
}

void Toll::Add(Car* car) {
  cars_.push_back(car);
}

std::vector<Car*> Toll::Remove() {
  return Remove(cars_.size());
}

std::vector<Car*> Toll::Remove(size_t num_cars) {
  std::vector<Car*> ret;
  if (cars_.size() > num_cars) {
    ret.insert(ret.end(), cars_.begin(), cars_.begin() + num_cars);
    cars_.erase(cars_.begin(), cars_.begin() + num_cars);
  } else {
    ret = cars_;
    cars_.clear();
  }
  return ret;
}

size_t Toll::num_cars() const {
  return cars_.size();
}

}  // namespace oop_project
{'fraction_non_alphanumeric': 0.17491901897269782, 'fraction_numerical': 0.0037019898195279964, 'mean_word_length': 3.580508474576271, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '855140', 'n_tokens_mistral': 874, 'n_tokens_neox': 833, 'n_words': 167}