Skip to content
Open
20 changes: 14 additions & 6 deletions benches/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate esplugin;
use std::path::Path;

use criterion::Criterion;
use esplugin::{GameId, Plugin};
use esplugin::{GameId, ParseMode, Plugin};

// HearthFires.esm is a 3.8 MB file, so it's got plenty of content without being
// large enough to slow down benchmarking much.
Expand All @@ -19,22 +19,30 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut plugin = Plugin::new(GAME_ID, Path::new(PLUGIN_TO_PARSE));

b.iter(|| {
assert!(plugin.parse_file(true).is_ok());
assert!(plugin.parse_file(ParseMode::HeaderOnly).is_ok());
});
});

c.bench_function("Plugin.parse_file() full", |b| {
c.bench_function("Plugin.parse_file() record ids", |b| {
let mut plugin = Plugin::new(GAME_ID, Path::new(PLUGIN_TO_PARSE));

b.iter(|| {
assert!(plugin.parse_file(false).is_ok());
assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());
});
});

c.bench_function("Plugin.parse_file() full with records", |b| {
let mut plugin = Plugin::new(GAME_ID, Path::new(PLUGIN_TO_PARSE));

b.iter(|| {
assert!(plugin.parse_file(ParseMode::All).is_ok());
});
});

c.bench_function("Plugin.overlaps_with()", |b| {
let mut plugin = Plugin::new(GAME_ID, Path::new(PLUGIN_TO_PARSE));

assert!(plugin.parse_file(false).is_ok());
assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());

b.iter(|| {
assert!(plugin.overlaps_with(&plugin));
Expand All @@ -44,7 +52,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Plugin.count_override_records()", |b| {
let mut plugin = Plugin::new(GAME_ID, Path::new(PLUGIN_TO_PARSE));

assert!(plugin.parse_file(false).is_ok());
assert!(plugin.parse_file(ParseMode::RecordIds).is_ok());

b.iter(|| {
assert_eq!(plugin.count_override_records(), 1272);
Expand Down
16 changes: 13 additions & 3 deletions ffi/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{f32, mem, panic, ptr};
use libc::{c_char, c_float, size_t};

use constants::*;
use esplugin::Plugin;
use esplugin::{ParseMode, Plugin};
use helpers::*;

#[no_mangle]
Expand Down Expand Up @@ -45,8 +45,13 @@ pub unsafe extern "C" fn esp_plugin_parse(plugin_ptr: *mut Plugin, load_header_o
if plugin_ptr.is_null() {
ESP_ERROR_NULL_POINTER
} else {
let mode = if load_header_only {
ParseMode::HeaderOnly
} else {
ParseMode::RecordIds
};
let plugin = &mut *plugin_ptr;
match plugin.parse_file(load_header_only) {
match plugin.parse_file(mode) {
Ok(_) => ESP_OK,
Err(_) => ESP_ERROR_PARSE_ERROR,
}
Expand Down Expand Up @@ -177,7 +182,12 @@ pub unsafe extern "C" fn esp_plugin_is_valid(
Err(x) => return x,
};

*is_valid = Plugin::is_valid(mapped_game_id, rust_path, load_header_only);
let mode = if load_header_only {
ParseMode::HeaderOnly
} else {
ParseMode::RecordIds
};
*is_valid = Plugin::is_valid(mapped_game_id, rust_path, mode);

ESP_OK
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use std::convert::TryInto;

pub use crate::error::Error;
pub use crate::game_id::GameId;
pub use crate::plugin::Plugin;
pub use crate::plugin::{ParseMode, Plugin, PluginEntry};
pub use crate::record::{Record, RecordHeader};
pub use crate::subrecord::Subrecord;

mod error;
mod form_id;
Expand Down
Loading