Skip to content
Permalink
Browse files

remove unnecessary reset

  • Loading branch information...
ry committed Mar 15, 2019
1 parent 664d6f9 commit 1291e427cf228825cccc0c96b58313e826037ef3
Showing with 21 additions and 27 deletions.
  1. +1 −7 core/isolate.rs
  2. +2 −2 core/shared_queue.js
  3. +12 −12 core/shared_queue.rs
  4. +6 −6 core/shared_queue_test.js
@@ -347,12 +347,8 @@ impl<B: Behavior> Future for Isolate<B> {

while !self.polled_recently {
let mut completed_count = 0;

debug!("poll loop");

self.polled_recently = true;

self.shared.reset();
assert_eq!(self.shared.size(), 0);

let mut i = 0;
while i != self.pending_ops.len() {
@@ -376,10 +372,8 @@ impl<B: Behavior> Future for Isolate<B> {
}

if completed_count > 0 {
debug!("respond");
self.respond()?;
self.shared.reset();
debug!("after respond");
}
}

@@ -96,14 +96,14 @@
return sharedBytes.subarray(off, end);
}

function activeRecords() {
function size() {
return shared32[INDEX_NUM_RECORDS] - shared32[INDEX_NUM_SHIFTED_OFF];
}

window.Deno._sharedQueue = {
head,
numRecords,
activeRecords,
size,
push,
reset,
shift
@@ -63,7 +63,7 @@ impl SharedQueue {
unsafe { std::slice::from_raw_parts_mut(p, self.bytes.len() / 4) }
}

pub fn active_records(&self) -> usize {
pub fn size(&self) -> usize {
let s = self.as_u32_slice();
(s[INDEX_NUM_RECORDS] - s[INDEX_NUM_SHIFTED_OFF]) as usize
}
@@ -170,32 +170,32 @@ mod tests {
let r = vec![8, 9, 10, 11].into_boxed_slice();
assert!(q.push(r));
assert_eq!(q.num_records(), 3);
assert_eq!(q.active_records(), 3);
assert_eq!(q.size(), 3);

let r = q.shift().unwrap();
assert_eq!(r.as_ref(), vec![1, 2, 3, 4, 5].as_slice());
assert_eq!(q.num_records(), 3);
assert_eq!(q.active_records(), 2);
assert_eq!(q.size(), 2);

let r = q.shift().unwrap();
assert_eq!(r.as_ref(), vec![6, 7].as_slice());
assert_eq!(q.num_records(), 3);
assert_eq!(q.active_records(), 1);
assert_eq!(q.size(), 1);

let r = q.shift().unwrap();
assert_eq!(r.as_ref(), vec![8, 9, 10, 11].as_slice());
assert_eq!(q.num_records(), 3);
assert_eq!(q.active_records(), 0);
assert_eq!(q.size(), 0);

assert!(q.shift().is_none());
assert!(q.shift().is_none());

assert_eq!(q.num_records(), 3);
assert_eq!(q.active_records(), 0);
assert_eq!(q.size(), 0);

q.reset();
assert_eq!(q.num_records(), 0);
assert_eq!(q.active_records(), 0);
assert_eq!(q.size(), 0);
}

fn alloc_buf(byte_length: usize) -> Buf {
@@ -208,16 +208,16 @@ mod tests {
fn overflow() {
let mut q = SharedQueue::new(RECOMMENDED_SIZE);
assert!(q.push(alloc_buf(RECOMMENDED_SIZE - 1)));
assert_eq!(q.active_records(), 1);
assert_eq!(q.size(), 1);
assert!(!q.push(alloc_buf(2)));
assert_eq!(q.active_records(), 1);
assert_eq!(q.size(), 1);
assert!(q.push(alloc_buf(1)));
assert_eq!(q.active_records(), 2);
assert_eq!(q.size(), 2);

assert_eq!(q.shift().unwrap().len(), RECOMMENDED_SIZE - 1);
assert_eq!(q.active_records(), 1);
assert_eq!(q.size(), 1);
assert_eq!(q.shift().unwrap().len(), 1);
assert_eq!(q.active_records(), 0);
assert_eq!(q.size(), 0);

assert!(!q.push(alloc_buf(1)));
}
@@ -23,7 +23,7 @@ function main() {
r = new Uint8Array([8, 9, 10, 11]);
assert(q.push(r));
assert(q.numRecords() == 3);
assert(q.activeRecords() == 3);
assert(q.size() == 3);

r = q.shift();
assert(r.byteLength == 5);
@@ -33,14 +33,14 @@ function main() {
assert(r[3] == 4);
assert(r[4] == 5);
assert(q.numRecords() == 3);
assert(q.activeRecords() == 2);
assert(q.size() == 2);

r = q.shift();
assert(r.byteLength == 2);
assert(r[0] == 6);
assert(r[1] == 7);
assert(q.numRecords() == 3);
assert(q.activeRecords() == 1);
assert(q.size() == 1);

r = q.shift();
assert(r.byteLength == 4);
@@ -49,16 +49,16 @@ function main() {
assert(r[2] == 10);
assert(r[3] == 11);
assert(q.numRecords() == 3);
assert(q.activeRecords() == 0);
assert(q.size() == 0);

assert(q.shift() == null);
assert(q.shift() == null);
assert(q.numRecords() == 3);
assert(q.activeRecords() == 0);
assert(q.size() == 0);

q.reset();
assert(q.numRecords() == 0);
assert(q.activeRecords() == 0);
assert(q.size() == 0);
libdeno.print("shared_queue_test.js ok\n");
}

0 comments on commit 1291e42

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.