mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
refactor: use Mutex for ErrorBuffer (#9539)
RwLock should only be used in circumstatnces where it has some benefit. Multiple concurrent readers is usually an undesirable design bug.
This commit is contained in:
parent
d9b1f96897
commit
bb30e9291e
1 changed files with 6 additions and 12 deletions
18
cli/ast.rs
18
cli/ast.rs
|
@ -12,7 +12,7 @@ use std::fmt;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::RwLock;
|
use std::sync::Mutex;
|
||||||
use swc_common::chain;
|
use swc_common::chain;
|
||||||
use swc_common::comments::Comment;
|
use swc_common::comments::Comment;
|
||||||
use swc_common::comments::CommentKind;
|
use swc_common::comments::CommentKind;
|
||||||
|
@ -107,7 +107,7 @@ impl DiagnosticBuffer {
|
||||||
where
|
where
|
||||||
F: Fn(Span) -> Loc,
|
F: Fn(Span) -> Loc,
|
||||||
{
|
{
|
||||||
let s = error_buffer.0.read().unwrap().clone();
|
let s = error_buffer.0.lock().unwrap().clone();
|
||||||
let diagnostics = s
|
let diagnostics = s
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d| {
|
.map(|d| {
|
||||||
|
@ -134,18 +134,12 @@ impl DiagnosticBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A buffer for collecting errors from the AST parser.
|
/// A buffer for collecting errors from the AST parser.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ErrorBuffer(Arc<RwLock<Vec<Diagnostic>>>);
|
pub struct ErrorBuffer(Arc<Mutex<Vec<Diagnostic>>>);
|
||||||
|
|
||||||
impl ErrorBuffer {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self(Arc::new(RwLock::new(Vec::new())))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Emitter for ErrorBuffer {
|
impl Emitter for ErrorBuffer {
|
||||||
fn emit(&mut self, db: &DiagnosticBuilder) {
|
fn emit(&mut self, db: &DiagnosticBuilder) {
|
||||||
self.0.write().unwrap().push((**db).clone());
|
self.0.lock().unwrap().push((**db).clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,7 +359,7 @@ pub fn parse_with_source_map(
|
||||||
FileName::Custom(specifier.to_string()),
|
FileName::Custom(specifier.to_string()),
|
||||||
source.to_string(),
|
source.to_string(),
|
||||||
);
|
);
|
||||||
let error_buffer = ErrorBuffer::new();
|
let error_buffer = ErrorBuffer::default();
|
||||||
let syntax = get_syntax(media_type);
|
let syntax = get_syntax(media_type);
|
||||||
let input = StringInput::from(&*source_file);
|
let input = StringInput::from(&*source_file);
|
||||||
let comments = SingleThreadedComments::default();
|
let comments = SingleThreadedComments::default();
|
||||||
|
|
Loading…
Reference in a new issue