I am trying this new way to solve the dom_string problem. In this way, I think we can make all the string of the now dom_string unbreakable and maintain only one type of string in our public interface as well as we can have enough efficience.
Following this way, I will change the dom_node a little to verify the effectiveness of this method, any advice are welcomed. Thanks! On Wed, Jun 3, 2009 at 9:41 PM, <[email protected]> wrote: > Author: struggleyb > Date: Wed Jun 3 08:41:29 2009 > New Revision: 7700 > > URL: http://source.netsurf-browser.org?rev=7700&view=rev > Log: > Another method to deal with dom_strint issue. > > Added: > branches/struggleyb/libdom-remain/ > - copied from r7699, trunk/dom/ > Modified: > branches/struggleyb/libdom-remain/include/dom/core/string.h > branches/struggleyb/libdom-remain/src/core/string.c > > Modified: branches/struggleyb/libdom-remain/include/dom/core/string.h > URL: > http://source.netsurf-browser.org/branches/struggleyb/libdom-remain/include/dom/core/string.h?rev=7700&r1=7699&r2=7700&view=diff > ============================================================================== > --- branches/struggleyb/libdom-remain/include/dom/core/string.h (original) > +++ branches/struggleyb/libdom-remain/include/dom/core/string.h Wed Jun 3 > 08:41:29 2009 > @@ -14,6 +14,9 @@ > #include <dom/functypes.h> > #include <dom/core/exceptions.h> > > +struct lwc_context_s; > +struct lwc_string_s; > + > typedef struct dom_string dom_string; > > /* Claim a reference on a DOM string */ > @@ -24,6 +27,12 @@ > /* Create a DOM string from a string of characters */ > dom_exception dom_string_create(dom_alloc alloc, void *pw, > const uint8_t *ptr, size_t len, struct dom_string **str); > +/* Create a DOM string from a buffer > + * We will not alloc any memory in this method because the client provide > + * it. This function call mainly used for create a string from lwc_string */ > +dom_exception dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, > + struct lwc_context_s *ctx, struct lwc_string_s *str, > + struct dom_string **ret); > > /* Case sensitively compare two DOM strings */ > int dom_string_cmp(struct dom_string *s1, struct dom_string *s2); > > Modified: branches/struggleyb/libdom-remain/src/core/string.c > URL: > http://source.netsurf-browser.org/branches/struggleyb/libdom-remain/src/core/string.c?rev=7700&r1=7699&r2=7700&view=diff > ============================================================================== > --- branches/struggleyb/libdom-remain/src/core/string.c (original) > +++ branches/struggleyb/libdom-remain/src/core/string.c Wed Jun 3 08:41:29 > 2009 > @@ -9,6 +9,7 @@ > #include <inttypes.h> > #include <string.h> > > +#include <libwapcaplet/libwapcaplet.h> > #include <parserutils/charset/utf8.h> > > #include <dom/core/string.h> > @@ -25,6 +26,10 @@ > uint8_t *ptr; /**< Pointer to string data */ > > size_t len; /**< Byte length of string */ > + > + lwc_string *intern; /**< The lwc_string of this string */ > + > + lwc_context *context; /**< The lwc_context for the > lwc_string */ > > dom_alloc alloc; /**< Memory (de)allocation function */ > void *pw; /**< Client-specific data */ > @@ -35,6 +40,8 @@ > static struct dom_string empty_string = { > .ptr = NULL, > .len = 0, > + .intern = NULL, > + .context = NULL, > .alloc = NULL, > .pw = NULL, > .refcnt = 1 > @@ -61,7 +68,10 @@ > void dom_string_unref(struct dom_string *str) > { > if (--str->refcnt == 0) { > - if (str->alloc != NULL) { > + if (str->intern != NULL) { > + lwc_context_string_unref(str->context, str->intern); > + str->alloc(str, 0, str->pw); > + } else if (str->alloc != NULL) { > str->alloc(str->ptr, 0, str->pw); > str->alloc(str, 0, str->pw); > } > @@ -119,6 +129,40 @@ > *str = ret; > > return DOM_NO_ERR; > +} > + > +/** > + * Create a dom_string from a lwc_string > + * > + * \param ctx The lwc_context > + * \param str The lwc_string > + * \param ret The new dom_string > + */ > +dom_exception dom_string_create_from_lwcstring(dom_alloc alloc, void *pw, > + lwc_context *ctx, lwc_string *str, struct dom_string **ret) > +{ > + dom_string *r; > + > + r = alloc(NULL, sizeof(struct dom_string), pw); > + if (r == NULL) > + return DOM_NO_MEM_ERR; > + > + r->context = ctx; > + r->intern = str; > + r->ptr = (uint8_t *)lwc_string_data(str); > + r->len = lwc_string_length(str); > + > + r->alloc = alloc; > + r->pw = pw; > + > + r->refcnt = 1; > + > + /* Ref the lwc_string */ > + lwc_context_string_ref(ctx, str); > + > + *ret = r; > + return DOM_NO_ERR; > + > } > > /** > > > _______________________________________________ > netsurf-commits mailing list > [email protected] > http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org >
