avm2: Don't mutably borrow for pos()
This commit is contained in:
parent
96f89a1643
commit
d5c2e5559b
|
@ -2393,14 +2393,14 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> {
|
|||
) -> Result<FrameControl<'gc>, Error> {
|
||||
let index = self.context.avm2.pop().coerce_to_i32(self)?;
|
||||
|
||||
//TODO: can we just subtract the size of *this* op to save some of this maths
|
||||
let offset = case_offsets
|
||||
.get(index as usize)
|
||||
.copied()
|
||||
.unwrap_or(default_offset)
|
||||
+ current_pos as i32;
|
||||
let current_pos = reader.pos(full_data) as i32;
|
||||
reader.seek(full_data, offset - current_pos);
|
||||
+ current_pos as i32
|
||||
- reader.pos(full_data) as i32;
|
||||
|
||||
reader.seek(full_data, offset);
|
||||
|
||||
Ok(FrameControl::Continue)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@ impl<'a> ReadSwfExt<'a> for Reader<'a> {
|
|||
fn as_mut_slice(&mut self) -> &mut &'a [u8] {
|
||||
&mut self.input
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn as_slice(&self) -> &'a [u8] {
|
||||
&self.input
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Reader<'a> {
|
||||
|
|
|
@ -12,6 +12,11 @@ impl<'a> ReadSwfExt<'a> for Reader<'a> {
|
|||
fn as_mut_slice(&mut self) -> &mut &'a [u8] {
|
||||
&mut self.input
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn as_slice(&self) -> &'a [u8] {
|
||||
&self.input
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Reader<'a> {
|
||||
|
|
|
@ -6,9 +6,15 @@ use std::io::{self, Read};
|
|||
pub trait ReadSwfExt<'a> {
|
||||
fn as_mut_slice(&mut self) -> &mut &'a [u8];
|
||||
|
||||
fn as_slice(&self) -> &'a [u8];
|
||||
|
||||
fn pos(&self, data: &[u8]) -> usize {
|
||||
self.as_slice().as_ptr() as usize - data.as_ptr() as usize
|
||||
}
|
||||
|
||||
// TODO: Make this fallible?
|
||||
fn seek(&mut self, data: &'a [u8], relative_offset: isize) {
|
||||
let mut pos = self.as_mut_slice().as_ptr() as usize - data.as_ptr() as usize;
|
||||
let mut pos = self.pos(data);
|
||||
pos = (pos as isize + relative_offset) as usize;
|
||||
pos = pos.min(data.len());
|
||||
*self.as_mut_slice() = &data[pos..];
|
||||
|
|
|
@ -243,6 +243,11 @@ impl<'a> ReadSwfExt<'a> for Reader<'a> {
|
|||
fn as_mut_slice(&mut self) -> &mut &'a [u8] {
|
||||
&mut self.input
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn as_slice(&self) -> &'a [u8] {
|
||||
&self.input
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Reader<'a> {
|
||||
|
|
Loading…
Reference in New Issue