Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't store the file path in the Run #616

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/balanced_pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn fake_splits(c: &mut Criterion) {

fn actual_splits(c: &mut Criterion) {
let buf = fs::read_to_string("tests/run_files/livesplit1.6.lss").unwrap();
let mut run = livesplit::parse(&buf, None).unwrap();
let mut run = livesplit::parse(&buf).unwrap();
run.comparison_generators_mut().clear();
run.comparison_generators_mut().push(Box::new(BalancedPB));

Expand Down
2 changes: 1 addition & 1 deletion benches/layout_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn artificial() -> (Timer, Layout) {

fn real() -> (Timer, Layout) {
let buf = fs::read_to_string("tests/run_files/Celeste - Any% (1.2.1.5).lss").unwrap();
let run = livesplit::parse(&buf, None).unwrap();
let run = livesplit::parse(&buf).unwrap();

let mut timer = Timer::new(run).unwrap();
timer.start();
Expand Down
6 changes: 3 additions & 3 deletions benches/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ fn huge_game_icon(c: &mut Criterion) {
let buf = fs::read_to_string("tests/run_files/livesplit1.6_gametime.lss").unwrap();

c.bench_function("Parse With Huge Game Icon", move |b| {
b.iter(|| livesplit::parse(&buf, None).unwrap())
b.iter(|| livesplit::parse(&buf).unwrap())
});
}

fn lots_of_icons(c: &mut Criterion) {
let buf = fs::read_to_string("tests/run_files/Celeste - Any% (1.2.1.5).lss").unwrap();

c.bench_function("Parse with lots of Icons", move |b| {
b.iter(|| livesplit::parse(&buf, None).unwrap())
b.iter(|| livesplit::parse(&buf).unwrap())
});
}

fn no_icons(c: &mut Criterion) {
let buf = fs::read_to_string("tests/run_files/livesplit1.6.lss").unwrap();

c.bench_function("Parse without Icons", move |b| {
b.iter(|| livesplit::parse(&buf, None).unwrap())
b.iter(|| livesplit::parse(&buf).unwrap())
});
}
2 changes: 1 addition & 1 deletion benches/scene_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ cfg_if::cfg_if! {
}

fn lss(path: &str) -> Run {
livesplit::parse(&file(path), None).unwrap()
livesplit::parse(&file(path)).unwrap()
}

fn lsl(path: &str) -> Layout {
Expand Down
2 changes: 1 addition & 1 deletion benches/software_rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cfg_if::cfg_if! {
}

fn lss(path: &str) -> Run {
livesplit::parse(&file(path), None).unwrap()
livesplit::parse(&file(path)).unwrap()
}

fn lsl(path: &str) -> Layout {
Expand Down
6 changes: 3 additions & 3 deletions capi/bind_gen/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
for (i, (name, typ)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down Expand Up @@ -417,15 +417,15 @@ namespace LiveSplitCore
writer,
"{}",
r#"
public static ParseRunResult Parse(Stream stream, string path, bool loadFiles)
public static ParseRunResult Parse(Stream stream, string loadFilesPath)
{
var data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
IntPtr pnt = Marshal.AllocHGlobal(data.Length);
try
{
Marshal.Copy(data, 0, pnt, data.Length);
return Parse(pnt, data.Length, path, loadFiles);
return Parse(pnt, data.Length, loadFilesPath);
}
finally
{
Expand Down
6 changes: 3 additions & 3 deletions capi/bind_gen/src/java/jna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
for (i, (name, typ)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down Expand Up @@ -409,7 +409,7 @@ public class {class} extends {base_class} implements AutoCloseable {{
writer,
"{}",
r#"
public static ParseRunResult parse(java.io.InputStream stream, String path, boolean loadFiles) throws java.io.IOException {
public static ParseRunResult parse(java.io.InputStream stream, String loadFilesPath) throws java.io.IOException {
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (true) {
Expand All @@ -420,7 +420,7 @@ public class {class} extends {base_class} implements AutoCloseable {{
byte[] arr = out.toByteArray();
java.nio.ByteBuffer nativeBuf = java.nio.ByteBuffer.allocateDirect(arr.length);
nativeBuf.put(arr);
return Run.parse(Native.getDirectBufferPointer(nativeBuf), arr.length, path, loadFiles);
return Run.parse(Native.getDirectBufferPointer(nativeBuf), arr.length, loadFilesPath);
}"#
)?;
}
Expand Down
6 changes: 3 additions & 3 deletions capi/bind_gen/src/java/jni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, class_name: &str) -> R
for (i, (name, typ)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down Expand Up @@ -373,8 +373,8 @@ public class {class} extends {base_class} implements AutoCloseable {{
writer,
"{}",
r#"
public static ParseRunResult parse(String data, String path, boolean loadFiles) {
ParseRunResult result = new ParseRunResult(LiveSplitCoreNative.Run_parseString(data, path, loadFiles));
public static ParseRunResult parse(String data, String loadFilesPath) {
ParseRunResult result = new ParseRunResult(LiveSplitCoreNative.Run_parseString(data, loadFilesPath));
return result;
}"#
)?;
Expand Down
8 changes: 4 additions & 4 deletions capi/bind_gen/src/jni_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ pub fn write<W: Write>(mut writer: W, classes: &BTreeMap<String, Class>) -> Resu

using namespace LiveSplit;

extern "C" JNIEXPORT jlong Java_livesplitcore_LiveSplitCoreNative_Run_1parseString(JNIEnv* jni_env, jobject, jstring data, jstring path, jboolean load_files) {
extern "C" JNIEXPORT jlong Java_livesplitcore_LiveSplitCoreNative_Run_1parseString(JNIEnv* jni_env, jobject, jstring data, jstring load_files_path) {
auto cstr_data = jni_env->GetStringUTFChars(data, nullptr);
auto cstr_path = jni_env->GetStringUTFChars(path, nullptr);
auto result = (jlong)Run_parse(cstr_data, strlen(cstr_data), cstr_path, (uint8_t)load_files);
jni_env->ReleaseStringUTFChars(path, cstr_path);
auto cstr_load_files_path = jni_env->GetStringUTFChars(load_files_path, nullptr);
auto result = (jlong)Run_parse(cstr_data, strlen(cstr_data), cstr_load_files_path);
jni_env->ReleaseStringUTFChars(load_files_path, cstr_load_files_path);
jni_env->ReleaseStringUTFChars(data, cstr_data);
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions capi/bind_gen/src/kotlin/jni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function) -> Result<()> {
for (i, (name, typ)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down Expand Up @@ -411,8 +411,8 @@ open class {class} : {base_class}, AutoCloseable {{
writer,
"{}",
r#"
fun parse(data: String, path: String, loadFiles: Boolean): ParseRunResult {
val result = ParseRunResult(LiveSplitCoreNative.Run_parseString(data, path, loadFiles))
fun parse(data: String, loadFilesPath: String): ParseRunResult {
val result = ParseRunResult(LiveSplitCoreNative.Run_parseString(data, loadFilesPath))
return result
}"#
)?;
Expand Down
37 changes: 17 additions & 20 deletions capi/bind_gen/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, type_script: bool) ->
}

if !type_script {
for (name, ty) in function.inputs.iter().skip(if is_static { 0 } else { 1 }) {
for (name, ty) in function.inputs.iter().skip(usize::from(!is_static)) {
write!(
writer,
r#"
Expand Down Expand Up @@ -175,7 +175,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, type_script: bool) ->
for (i, (name, ty)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down Expand Up @@ -621,20 +621,20 @@ const liveSplitCoreNative = ffi.Library('livesplit_core', {"#
writer,
"{}",
r#"
static parseArray(data: Int8Array, path: string, loadFiles: boolean): ParseRunResult {
static parseArray(data: Int8Array, loadFilesPath: string): ParseRunResult {
let buf = Buffer.from(data.buffer);
if (data.byteLength !== data.buffer.byteLength) {
buf = buf.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
return Run.parse(buf, buf.byteLength, path, loadFiles);
return Run.parse(buf, buf.byteLength, loadFilesPath);
}
static parseFile(file: any, path: string, loadFiles: boolean): ParseRunResult {
static parseFile(file: any, loadFilesPath: string): ParseRunResult {
const data = fs.readFileSync(file);
return Run.parse(data, data.byteLength, path, loadFiles);
return Run.parse(data, data.byteLength, loadFilesPath);
}
static parseString(text: string, path: string, loadFiles: boolean): ParseRunResult {
static parseString(text: string, loadFilesPath: string): ParseRunResult {
const data = new Buffer(text);
return Run.parse(data, data.byteLength, path, loadFiles);
return Run.parse(data, data.byteLength, loadFilesPath);
}"#
)?;
} else {
Expand All @@ -644,36 +644,33 @@ const liveSplitCoreNative = ffi.Library('livesplit_core', {"#
r#"
/**
* @param {Int8Array} data
* @param {string} path
* @param {boolean} loadFiles
* @param {string} loadFilesPath
* @return {ParseRunResult}
*/
static parseArray(data, path, loadFiles) {
static parseArray(data, loadFilesPath) {
let buf = Buffer.from(data.buffer);
if (data.byteLength !== data.buffer.byteLength) {
buf = buf.slice(data.byteOffset, data.byteOffset + data.byteLength);
}
return Run.parse(buf, buf.byteLength, path, loadFiles);
return Run.parse(buf, buf.byteLength, loadFilesPath);
}
/**
* @param {string | Buffer | number} file
* @param {string} path
* @param {boolean} loadFiles
* @param {string} loadFilesPath
* @return {ParseRunResult}
*/
static parseFile(file, path, loadFiles) {
static parseFile(file, loadFilesPath) {
const data = fs.readFileSync(file);
return Run.parse(data, data.byteLength, path, loadFiles);
return Run.parse(data, data.byteLength, loadFilesPath);
}
/**
* @param {string} text
* @param {string} path
* @param {boolean} loadFiles
* @param {string} loadFilesPath
* @return {ParseRunResult}
*/
static parseString(text, path, loadFiles) {
static parseString(text, loadFilesPath) {
const data = new Buffer(text);
return Run.parse(data, data.byteLength, path, loadFiles);
return Run.parse(data, data.byteLength, loadFilesPath);
}"#
)?;
}
Expand Down
4 changes: 2 additions & 2 deletions capi/bind_gen/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ class {class}({base_class}):"#,
writer,
r#"
@staticmethod
def parse_file(file, path, load_files):
def parse_file(file, load_files_path):
data = file.read()
if sys.version_info[0] > 2:
if isinstance(data, str):
raise TypeError("File must be opened in binary mode!")
bytes = bytearray(data)
bufferType = c_byte * len(bytes)
buffer = bufferType(*bytes)
return Run.parse(buffer, len(bytes), path, load_files)"#
return Run.parse(buffer, len(bytes), load_files_path)"#
)?;
}

Expand Down
4 changes: 2 additions & 2 deletions capi/bind_gen/src/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function) -> Result<()> {
)?;
}

for (name, typ) in function.inputs.iter().skip(if is_static { 0 } else { 1 }) {
for (name, typ) in function.inputs.iter().skip(usize::from(!is_static)) {
write!(
writer,
r"
Expand Down Expand Up @@ -150,7 +150,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function) -> Result<()> {
for (i, (name, _)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down
2 changes: 1 addition & 1 deletion capi/bind_gen/src/swift/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function) -> Result<()> {
for (i, (name, ty)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down
26 changes: 12 additions & 14 deletions capi/bind_gen/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, type_script: bool) ->
}

if !type_script {
for (name, ty) in function.inputs.iter().skip(if is_static { 0 } else { 1 }) {
for (name, ty) in function.inputs.iter().skip(usize::from(!is_static)) {
write!(
writer,
r#"
Expand Down Expand Up @@ -148,7 +148,7 @@ fn write_fn<W: Write>(mut writer: W, function: &Function, type_script: bool) ->
for (i, (name, ty)) in function
.inputs
.iter()
.skip(if is_static { 0 } else { 1 })
.skip(usize::from(!is_static))
.enumerate()
{
if i != 0 {
Expand Down Expand Up @@ -894,15 +894,15 @@ function dealloc(slice) {
writer,
"{}",
r#"
static parseArray(data: Int8Array, path: string, loadFiles: boolean): ParseRunResult {
static parseArray(data: Int8Array, loadFilesPath: string): ParseRunResult {
const slice = allocInt8Array(data);
const result = Run.parse(slice.ptr, slice.len, path, loadFiles);
const result = Run.parse(slice.ptr, slice.len, loadFilesPath);
dealloc(slice);
return result;
}
static parseString(text: string, path: string, loadFiles: boolean): ParseRunResult {
static parseString(text: string, loadFilesPath: string): ParseRunResult {
const slice = allocString(text);
const result = Run.parse(slice.ptr, slice.len, path, loadFiles);
const result = Run.parse(slice.ptr, slice.len, loadFilesPath);
dealloc(slice);
return result;
}"#
Expand All @@ -914,25 +914,23 @@ function dealloc(slice) {
r#"
/**
* @param {Int8Array} data
* @param {string} path
* @param {boolean} loadFiles
* @param {string} loadFilesPath
* @return {ParseRunResult}
*/
static parseArray(data, path, loadFiles) {
static parseArray(data, loadFilesPath) {
const slice = allocInt8Array(data);
const result = Run.parse(slice.ptr, slice.len, path, loadFiles);
const result = Run.parse(slice.ptr, slice.len, loadFilesPath);
dealloc(slice);
return result;
}
/**
* @param {string} text
* @param {string} path
* @param {boolean} loadFiles
* @param {string} loadFilesPath
* @return {ParseRunResult}
*/
static parseString(text, path, loadFiles) {
static parseString(text, loadFilesPath) {
const slice = allocString(text);
const result = Run.parse(slice.ptr, slice.len, path, loadFiles);
const result = Run.parse(slice.ptr, slice.len, loadFilesPath);
dealloc(slice);
return result;
}"#
Expand Down
Loading