Skip to content

Commit 1e411e7

Browse files
95thTzikas
authored andcommitted
Minor tweaks (#2569)
1. Separate Snapshot and Script StartupData functions based on cfg "no-snapshot-init" 2. Replace deprecated Once::ONCE_INIT with Once::new (rust-lang/rust#61757) 3. Elide lifetime 4. Fix typos
1 parent 467a1f5 commit 1e411e7

File tree

2 files changed

+60
-55
lines changed

2 files changed

+60
-55
lines changed

cli/startup_data.rs

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2-
use deno::{Script, StartupData};
2+
#[cfg(feature = "no-snapshot-init")]
3+
use deno::Script;
34

5+
use deno::StartupData;
6+
7+
#[cfg(feature = "no-snapshot-init")]
8+
pub fn deno_isolate_init() -> StartupData<'static> {
9+
debug!("Deno isolate init without snapshots.");
10+
#[cfg(not(feature = "check-only"))]
11+
let source =
12+
include_str!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/main.js"));
13+
#[cfg(feature = "check-only")]
14+
let source = "";
15+
16+
StartupData::Script(Script {
17+
filename: "gen/cli/bundle/main.js",
18+
source,
19+
})
20+
}
21+
22+
#[cfg(not(feature = "no-snapshot-init"))]
423
pub fn deno_isolate_init() -> StartupData<'static> {
5-
if cfg!(feature = "no-snapshot-init") {
6-
debug!("Deno isolate init without snapshots.");
7-
#[cfg(not(feature = "check-only"))]
8-
let source_bytes =
9-
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/main.js"));
10-
#[cfg(feature = "check-only")]
11-
let source_bytes = b"";
12-
13-
StartupData::Script(Script {
14-
filename: "gen/cli/bundle/main.js",
15-
source: std::str::from_utf8(&source_bytes[..]).unwrap(),
16-
})
17-
} else {
18-
debug!("Deno isolate init with snapshots.");
19-
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
20-
let data =
21-
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
22-
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
23-
let data = b"";
24-
25-
StartupData::Snapshot(data)
26-
}
24+
debug!("Deno isolate init with snapshots.");
25+
#[cfg(not(feature = "check-only"))]
26+
let data =
27+
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
28+
#[cfg(feature = "check-only")]
29+
let data = b"";
30+
31+
StartupData::Snapshot(data)
2732
}
2833

34+
#[cfg(feature = "no-snapshot-init")]
2935
pub fn compiler_isolate_init() -> StartupData<'static> {
30-
if cfg!(feature = "no-snapshot-init") {
31-
debug!("Compiler isolate init without snapshots.");
32-
#[cfg(not(feature = "check-only"))]
33-
let source_bytes = include_bytes!(concat!(
34-
env!("GN_OUT_DIR"),
35-
"/gen/cli/bundle/compiler.js"
36-
));
37-
#[cfg(feature = "check-only")]
38-
let source_bytes = b"";
39-
40-
StartupData::Script(Script {
41-
filename: "gen/cli/bundle/compiler.js",
42-
source: std::str::from_utf8(&source_bytes[..]).unwrap(),
43-
})
44-
} else {
45-
debug!("Deno isolate init with snapshots.");
46-
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
47-
let data = include_bytes!(concat!(
48-
env!("GN_OUT_DIR"),
49-
"/gen/cli/snapshot_compiler.bin"
50-
));
51-
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
52-
let data = b"";
53-
54-
StartupData::Snapshot(data)
55-
}
36+
debug!("Compiler isolate init without snapshots.");
37+
#[cfg(not(feature = "check-only"))]
38+
let source =
39+
include_str!(concat!(env!("GN_OUT_DIR"), "/gen/cli/bundle/compiler.js"));
40+
#[cfg(feature = "check-only")]
41+
let source = "";
42+
43+
StartupData::Script(Script {
44+
filename: "gen/cli/bundle/compiler.js",
45+
source,
46+
})
47+
}
48+
49+
#[cfg(not(feature = "no-snapshot-init"))]
50+
pub fn compiler_isolate_init() -> StartupData<'static> {
51+
debug!("Deno isolate init with snapshots.");
52+
#[cfg(not(feature = "check-only"))]
53+
let data = include_bytes!(concat!(
54+
env!("GN_OUT_DIR"),
55+
"/gen/cli/snapshot_compiler.bin"
56+
));
57+
#[cfg(feature = "check-only")]
58+
let data = b"";
59+
60+
StartupData::Snapshot(data)
5661
}

core/isolate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use libc::c_void;
2525
use std::ffi::CStr;
2626
use std::ffi::CString;
2727
use std::ptr::null;
28-
use std::sync::{Arc, Mutex, Once, ONCE_INIT};
28+
use std::sync::{Arc, Mutex, Once};
2929

3030
pub type Buf = Box<[u8]>;
3131

@@ -55,8 +55,8 @@ struct OwnedScript {
5555
pub filename: String,
5656
}
5757

58-
impl<'a> From<Script<'a>> for OwnedScript {
59-
fn from(s: Script<'a>) -> OwnedScript {
58+
impl From<Script<'_>> for OwnedScript {
59+
fn from(s: Script) -> OwnedScript {
6060
OwnedScript {
6161
source: s.source.to_string(),
6262
filename: s.filename.to_string(),
@@ -133,10 +133,10 @@ impl Drop for Isolate {
133133
}
134134
}
135135

136-
static DENO_INIT: Once = ONCE_INIT;
136+
static DENO_INIT: Once = Once::new();
137137

138138
impl Isolate {
139-
/// startup_data defines the snapshot or script used at startup to initalize
139+
/// startup_data defines the snapshot or script used at startup to initialize
140140
/// the isolate.
141141
pub fn new(startup_data: StartupData, will_snapshot: bool) -> Self {
142142
DENO_INIT.call_once(|| {
@@ -157,7 +157,7 @@ impl Isolate {
157157

158158
let mut startup_script: Option<OwnedScript> = None;
159159

160-
// Seperate into Option values for each startup type
160+
// Separate into Option values for each startup type
161161
match startup_data {
162162
StartupData::Script(d) => {
163163
startup_script = Some(d.into());

0 commit comments

Comments
 (0)