avm2: Cache method body index on Method
This commit is contained in:
parent
8ab225aa90
commit
176b70b1cd
|
@ -166,6 +166,7 @@ impl<'gc> BytecodeMethod<'gc> {
|
|||
let abc = txunit.abc();
|
||||
let mut signature = Vec::new();
|
||||
let mut return_type = Multiname::any();
|
||||
let mut abc_method_body = None;
|
||||
|
||||
if abc.methods.get(abc_method.0 as usize).is_some() {
|
||||
let method = &abc.methods[abc_method.0 as usize];
|
||||
|
@ -178,20 +179,8 @@ impl<'gc> BytecodeMethod<'gc> {
|
|||
.deref()
|
||||
.clone();
|
||||
|
||||
for (index, method_body) in abc.method_bodies.iter().enumerate() {
|
||||
if method_body.method.0 == abc_method.0 {
|
||||
return Ok(Self {
|
||||
txunit,
|
||||
abc: txunit.abc(),
|
||||
abc_method: abc_method.0,
|
||||
abc_method_body: Some(index as u32),
|
||||
verified_info: GcCell::new(activation.context.gc_context, None),
|
||||
signature,
|
||||
return_type,
|
||||
is_function,
|
||||
activation_class: Lock::new(None),
|
||||
});
|
||||
}
|
||||
if let Some(body) = method.body {
|
||||
abc_method_body = Some(body.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +188,7 @@ impl<'gc> BytecodeMethod<'gc> {
|
|||
txunit,
|
||||
abc: txunit.abc(),
|
||||
abc_method: abc_method.0,
|
||||
abc_method_body: None,
|
||||
abc_method_body,
|
||||
verified_info: GcCell::new(activation.context.gc_context, None),
|
||||
signature,
|
||||
return_type,
|
||||
|
|
|
@ -67,8 +67,14 @@ impl<'a> Reader<'a> {
|
|||
|
||||
let len = self.read_u30()?;
|
||||
let mut method_bodies = Vec::with_capacity(len as usize);
|
||||
for _ in 0..len {
|
||||
method_bodies.push(self.read_method_body()?);
|
||||
for body_idx in 0..len {
|
||||
let body = self.read_method_body()?;
|
||||
if methods[body.method.0 as usize].body.is_some() {
|
||||
// TODO: this should somehow throw error 1121 in FP.
|
||||
return Err(Error::invalid_data("Duplicate method body"));
|
||||
}
|
||||
methods[body.method.0 as usize].body = Some(Index::new(body_idx));
|
||||
method_bodies.push(body);
|
||||
}
|
||||
|
||||
Ok(AbcFile {
|
||||
|
@ -279,6 +285,7 @@ impl<'a> Reader<'a> {
|
|||
params,
|
||||
return_type,
|
||||
flags,
|
||||
body: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,8 @@ pub struct Method {
|
|||
pub params: Vec<MethodParam>,
|
||||
pub return_type: Index<Multiname>,
|
||||
pub flags: MethodFlags,
|
||||
// not an ABC MethodInfo property; bound when parsing MethodBodies
|
||||
pub body: Option<Index<MethodBody>>,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
|
|
@ -2688,12 +2688,14 @@ pub fn avm2_tests() -> Vec<Avm2TestData> {
|
|||
params: vec![],
|
||||
return_type: Index::new(1),
|
||||
flags: MethodFlags::empty(),
|
||||
body: Some(Index::new(0)),
|
||||
},
|
||||
Method {
|
||||
name: Index::new(0),
|
||||
params: vec![],
|
||||
return_type: Index::new(0),
|
||||
flags: MethodFlags::empty(),
|
||||
body: Some(Index::new(1)),
|
||||
},
|
||||
],
|
||||
metadata: vec![],
|
||||
|
|
Loading…
Reference in New Issue