[librsvg] Defs: store the externs as HashMap<AllowedUrl, handle> instead of a String key
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Defs: store the externs as HashMap<AllowedUrl, handle> instead of a String key
- Date: Sat, 1 Dec 2018 01:56:12 +0000 (UTC)
commit a78864b7e9caedd84f95455e140bcd4960dc125b
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 30 19:27:47 2018 -0600
Defs: store the externs as HashMap<AllowedUrl, handle> instead of a String key
Also, make rsvg_handle_load_extern() take a GFile directly.
librsvg/rsvg-handle.c | 32 ++++++++++----------------------
librsvg/rsvg-private.h | 2 +-
rsvg_internals/src/allowed_url.rs | 2 +-
rsvg_internals/src/defs.rs | 4 ++--
rsvg_internals/src/handle.rs | 8 +++++---
5 files changed, 19 insertions(+), 29 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index 9ae4d1a2..fecd32d8 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -1030,31 +1030,19 @@ rsvg_handle_get_css_styles (RsvgHandle *handle)
}
RsvgHandle *
-rsvg_handle_load_extern (RsvgHandle *handle, const char *uri)
+rsvg_handle_load_extern (RsvgHandle *handle, GFile *file)
{
- RsvgHandle *res = NULL;
- GInputStream *stream;
+ RsvgHandle *res;
- stream = rsvg_handle_acquire_stream (handle, uri, NULL);
+ res = rsvg_handle_new_from_gfile_sync (file,
+ handle->priv->flags,
+ NULL,
+ NULL);
- if (stream) {
- GFile *file = g_file_new_for_uri (uri);
-
- res = rsvg_handle_new_from_stream_sync (stream,
- file,
- handle->priv->flags,
- NULL,
- NULL);
-
- g_object_unref (file);
-
- if (res) {
- rsvg_tree_cascade (res->priv->tree);
- } else {
- /* FIXME: rsvg_log!("could not load external resource"); */
- }
-
- g_object_unref (stream);
+ if (res) {
+ rsvg_tree_cascade (res->priv->tree);
+ } else {
+ /* FIXME: rsvg_log!("could not load external resource"); */
}
return res;
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index a353b602..00bcf203 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -271,7 +271,7 @@ GFile *rsvg_handle_rust_get_base_gfile (RsvgHandleRust *raw_handle);
G_GNUC_INTERNAL
RsvgHandle *rsvg_handle_load_extern (RsvgHandle *handle,
- const char *uri);
+ GFile *file);
G_GNUC_INTERNAL
gboolean rsvg_handle_keep_image_data (RsvgHandle *handle);
diff --git a/rsvg_internals/src/allowed_url.rs b/rsvg_internals/src/allowed_url.rs
index 53c00595..63e79577 100644
--- a/rsvg_internals/src/allowed_url.rs
+++ b/rsvg_internals/src/allowed_url.rs
@@ -11,7 +11,7 @@ use url::{self, Url};
/// a specified `href` (a possibly-relative filename, for example)
/// should be allowed to be loaded, given the base URL of the SVG
/// being loaded.
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq, Hash)]
pub struct AllowedUrl(Url);
#[derive(Debug, PartialEq)]
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index 96651304..6f50cd63 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -17,7 +17,7 @@ pub enum RsvgDefs {}
pub struct Defs {
nodes: HashMap<String, Rc<Node>>,
- externs: HashMap<String, *const RsvgHandle>,
+ externs: HashMap<AllowedUrl, *const RsvgHandle>,
}
impl Defs {
@@ -60,7 +60,7 @@ impl Defs {
let aurl =
AllowedUrl::from_href(href, handle::get_base_url(handle).as_ref()).map_err(|_| ())?;
- match self.externs.entry(aurl.url().as_str().to_string()) {
+ match self.externs.entry(aurl) {
Entry::Occupied(e) => Ok(*(e.get())),
Entry::Vacant(e) => {
let extern_handle = handle::load_extern(handle, e.key())?;
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index dfd3c33f..6ea69552 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -41,7 +41,7 @@ extern "C" {
fn rsvg_handle_load_extern(
handle: *const RsvgHandle,
- href: *const libc::c_char,
+ file: *const gio_sys::GFile,
) -> *const RsvgHandle;
fn rsvg_handle_keep_image_data(handle: *const RsvgHandle) -> glib_sys::gboolean;
@@ -63,9 +63,11 @@ pub fn get_defs<'a>(handle: *const RsvgHandle) -> &'a mut Defs {
}
}
-pub fn load_extern(handle: *const RsvgHandle, uri: &str) -> Result<*const RsvgHandle, ()> {
+pub fn load_extern(handle: *const RsvgHandle, aurl: &AllowedUrl) -> Result<*const RsvgHandle, ()> {
unsafe {
- let res = rsvg_handle_load_extern(handle, uri.to_glib_none().0);
+ let file = GFile::new_for_uri(aurl.url().as_str());
+
+ let res = rsvg_handle_load_extern(handle, file.to_glib_none().0);
if res.is_null() {
Err(())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]