forked from BigfootDev/flatbuffers
[rust] Use read_scalar_at where possible (#5385)
This slightly improves readability.
This commit is contained in:
committed by
Robert Winslow
parent
16aef8ac0d
commit
b80ad7e439
@@ -21,7 +21,7 @@ use std::str::from_utf8_unchecked;
|
||||
|
||||
#[cfg(target_endian = "little")]
|
||||
use endian_scalar::EndianScalar;
|
||||
use endian_scalar::read_scalar;
|
||||
use endian_scalar::{read_scalar, read_scalar_at};
|
||||
use follow::Follow;
|
||||
use primitives::*;
|
||||
|
||||
@@ -61,7 +61,7 @@ impl<'a, T: SafeSliceAccess + 'a> Vector<'a, T> {
|
||||
let loc = self.1;
|
||||
let sz = size_of::<T>();
|
||||
debug_assert!(sz > 0);
|
||||
let len = read_scalar::<UOffsetT>(&buf[loc..loc + SIZE_UOFFSET]) as usize;
|
||||
let len = read_scalar_at::<UOffsetT>(&buf, loc) as usize;
|
||||
let data_buf = &buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len * sz];
|
||||
let ptr = data_buf.as_ptr() as *const T;
|
||||
let s: &'a [T] = unsafe { from_raw_parts(ptr, len) };
|
||||
@@ -100,7 +100,7 @@ pub fn follow_cast_ref<'a, T: Sized + 'a>(buf: &'a [u8], loc: usize) -> &'a T {
|
||||
impl<'a> Follow<'a> for &'a str {
|
||||
type Inner = &'a str;
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let len = read_scalar::<UOffsetT>(&buf[loc..loc + SIZE_UOFFSET]) as usize;
|
||||
let len = read_scalar_at::<UOffsetT>(&buf, loc) as usize;
|
||||
let slice = &buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len];
|
||||
let s = unsafe { from_utf8_unchecked(slice) };
|
||||
s
|
||||
@@ -111,7 +111,7 @@ impl<'a> Follow<'a> for &'a str {
|
||||
fn follow_slice_helper<T>(buf: &[u8], loc: usize) -> &[T] {
|
||||
let sz = size_of::<T>();
|
||||
debug_assert!(sz > 0);
|
||||
let len = read_scalar::<UOffsetT>(&buf[loc..loc + SIZE_UOFFSET]) as usize;
|
||||
let len = read_scalar_at::<UOffsetT>(&buf, loc) as usize;
|
||||
let data_buf = &buf[loc + SIZE_UOFFSET..loc + SIZE_UOFFSET + len * sz];
|
||||
let ptr = data_buf.as_ptr() as *const T;
|
||||
let s: &[T] = unsafe { from_raw_parts(ptr, len) };
|
||||
|
||||
Reference in New Issue
Block a user