Skip to content

Commit

Permalink
Merge pull request #2599 from iced-rs/replace-rc-with-arc-for-markdown
Browse files Browse the repository at this point in the history
Replace `Rc` with `Arc` for `markdown` caching
  • Loading branch information
hecrj authored Sep 21, 2024
2 parents 24150ef + 6d1ecb7 commit 88a2fac
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions widget/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::core::{
use crate::{column, container, rich_text, row, scrollable, span, text};

use std::cell::{Cell, RefCell};
use std::rc::Rc;
use std::sync::Arc;

pub use core::text::Highlight;
pub use pulldown_cmark::HeadingLevel;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub enum Item {
pub struct Text {
spans: Vec<Span>,
last_style: Cell<Option<Style>>,
last_styled_spans: RefCell<Rc<[text::Span<'static, Url>]>>,
last_styled_spans: RefCell<Arc<[text::Span<'static, Url>]>>,
}

impl Text {
Expand All @@ -104,7 +104,7 @@ impl Text {
///
/// This method performs caching for you. It will only reallocate if the [`Style`]
/// provided changes.
pub fn spans(&self, style: Style) -> Rc<[text::Span<'static, Url>]> {
pub fn spans(&self, style: Style) -> Arc<[text::Span<'static, Url>]> {
if Some(style) != self.last_style.get() {
*self.last_styled_spans.borrow_mut() =
self.spans.iter().map(|span| span.view(&style)).collect();
Expand Down

0 comments on commit 88a2fac

Please sign in to comment.