Skip to content
Permalink
Browse files

minor clean ups

  • Loading branch information...
ry committed Mar 15, 2019
1 parent 9cde01a commit cffe1d7863408528edc7fe6d3d978470524206dc
Showing with 4 additions and 11 deletions.
  1. +4 −11 core/shared_queue.rs
@@ -1,26 +1,19 @@
#![allow(dead_code)]

// Copyright 2018 the Deno authors. All rights reserved. MIT license.
use crate::isolate::Buf;
use crate::libdeno::deno_buf;

const MAX_RECORDS: usize = 100;

/// Total number of records added.
const INDEX_NUM_RECORDS: usize = 0;

/// Number of records that have been shifted off.
const INDEX_NUM_SHIFTED_OFF: usize = 1;

/// The head is the number of initialized bytes in SharedQueue.
/// It grows monotonically.
const INDEX_HEAD: usize = 2;

const INDEX_OFFSETS: usize = 3;
const INDEX_RECORDS: usize = 3 + MAX_RECORDS;

/// Byte offset of where the records begin. Also where the head starts.
const HEAD_INIT: usize = 4 * INDEX_RECORDS;

/// A rough guess at how big we should make the shared buffer in bytes.
pub const RECOMMENDED_SIZE: usize = 128 * MAX_RECORDS;

@@ -54,8 +47,7 @@ impl SharedQueue {

fn as_u32_slice<'a>(&'a self) -> &'a [u32] {
let p = self.bytes.as_ptr() as *const u32;
let s = unsafe { std::slice::from_raw_parts(p, self.bytes.len() / 4) };
s
unsafe { std::slice::from_raw_parts(p, self.bytes.len() / 4) }
}

fn as_u32_slice_mut<'a>(&'a mut self) -> &'a mut [u32] {
@@ -110,6 +102,7 @@ impl SharedQueue {
let u32_slice = self.as_u32_slice();
let i = u32_slice[INDEX_NUM_SHIFTED_OFF] as usize;
if i >= self.num_records() {
assert_eq!(self.size(), 0);
return None;
}
let off = self.get_offset(i).unwrap();
@@ -130,7 +123,7 @@ impl SharedQueue {
let end = off + record.len();
let index = self.num_records();
if end > self.bytes.len() {
println!("records_push fail");
eprintln!("WARNING the sharedQueue overflowed");
return false;
}
self.set_end(index, end);

0 comments on commit cffe1d7

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.