[librsvg] Use RefCell instead of UnsafeCell for FilterCtx::background_surface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Use RefCell instead of UnsafeCell for FilterCtx::background_surface
- Date: Fri, 6 Sep 2019 01:22:17 +0000 (UTC)
commit 5adb6bdb2f708113c4a6d9f8fb9c5b21a7268d3b
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Sep 5 20:18:57 2019 -0500
Use RefCell instead of UnsafeCell for FilterCtx::background_surface
UnsafeCell seems like premature optimization, perhaps?
rsvg_internals/src/filters/context.rs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index 3cfc9d69..6ac196c1 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -1,4 +1,4 @@
-use std::cell::UnsafeCell;
+use std::cell::RefCell;
use std::collections::HashMap;
use std::f64;
@@ -62,7 +62,7 @@ pub struct FilterContext {
/// Surfaces of the previous filter primitives by name.
previous_results: HashMap<String, FilterOutput>,
/// The background surface. Computed lazily.
- background_surface: UnsafeCell<Option<Result<SharedImageSurface, FilterError>>>,
+ background_surface: RefCell<Option<Result<SharedImageSurface, FilterError>>>,
/// The filter effects region.
effects_region: BoundingBox,
/// Whether the currently rendered filter primitive uses linear RGB for color operations.
@@ -157,7 +157,7 @@ impl FilterContext {
source_surface,
last_result: None,
previous_results: HashMap::new(),
- background_surface: UnsafeCell::new(None),
+ background_surface: RefCell::new(None),
effects_region: filter.compute_effects_region(
computed_from_node_being_filtered,
draw_ctx,
@@ -205,7 +205,7 @@ impl FilterContext {
{
// At this point either no, or only immutable references to background_surface exist, so
// it's ok to make an immutable reference.
- let bg = unsafe { &*self.background_surface.get() };
+ let bg = self.background_surface.borrow();
// If background_surface was already computed, return the immutable reference. It will
// get bound to the &self lifetime by the function return type.
@@ -216,7 +216,7 @@ impl FilterContext {
// If we got here, then background_surface hasn't been computed yet. This means there are
// no references to it and we can create a mutable reference.
- let bg = unsafe { &mut *self.background_surface.get() };
+ let mut bg = self.background_surface.borrow_mut();
*bg = Some(
cairo::ImageSurface::create(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]