avm2: Slightly improve findprop optimizations when property is found on script

This commit is contained in:
Lord-McSweeney 2024-05-22 19:29:56 -07:00 committed by Lord-McSweeney
parent b523ad4b32
commit 6acfc3953a
2 changed files with 6 additions and 21 deletions

View File

@ -850,15 +850,9 @@ pub fn optimize<'gc>(
// is unlikely to cause any real problems with SWFs.
*op = Op::GetScriptGlobals { script };
let script_globals = script.globals_if_init();
if let Some(script_globals) = script_globals {
if script.traits_loaded() {
stack_push_done = true;
if let Some(global_class) = script_globals.instance_of() {
stack.push_class_object(global_class);
} else {
stack.push_any();
}
stack.push_class(script.global_class());
}
}
}

View File

@ -585,6 +585,10 @@ impl<'gc> Script<'gc> {
self.0.read().translation_unit
}
pub fn traits_loaded(self) -> bool {
self.0.read().traits_loaded
}
pub fn global_class(self) -> Class<'gc> {
self.0
.read()
@ -636,19 +640,6 @@ impl<'gc> Script<'gc> {
}
}
/// Return the global scope for the script.
///
/// If the script has not yet been initialized, this will return None.
pub fn globals_if_init(&self) -> Option<Object<'gc>> {
let read = self.0.read();
if !read.initialized {
None
} else {
Some(read.globals)
}
}
/// Return traits for this script.
///
/// This function will return an error if it is incorrectly called before