Bug 98299 - String::remove will convert an 8 bit string to a 16 bit string
Summary: String::remove will convert an 8 bit string to a 16 bit string
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-03 14:16 PDT by Michael Saboff
Modified: 2022-02-27 23:24 PST (History)
2 users (show)

See Also:


Attachments
Patch (1.92 KB, patch)
2012-10-03 16:00 PDT, Michael Saboff
benjamin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Saboff 2012-10-03 14:16:09 PDT
The StringImpl::remove() method will up convert the contents of an 8 bit string and the result will always be a 16 bit string.
Comment 1 Michael Saboff 2012-10-03 14:19:41 PDT
The remove method is actually in WTFString.cpp (String::remove).
Comment 2 Michael Saboff 2012-10-03 16:00:05 PDT
Created attachment 166981 [details]
Patch
Comment 3 Benjamin Poulain 2012-10-03 17:43:16 PDT
Comment on attachment 166981 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166981&action=review

> Source/WTF/wtf/text/WTFString.cpp:281
>      if (static_cast<unsigned>(lengthToRemove) > length() - position)
>          lengthToRemove = length() - position;

No idea if that case is common.
If it is, shouldn't we just return a substring sharing impl here?

> Source/WTF/wtf/text/WTFString.cpp:289
> +        RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() - lengthToRemove, data);
> +        memcpy(data, characters8(), position * sizeof(LChar));
> +        memcpy(data + position, characters8() + position + lengthToRemove,
> +            (length() - lengthToRemove - position) * sizeof(LChar));
> +        m_impl = newImpl.release();

I would do an inline template with that code taking CharacterType as argument.
Comment 4 Michael Saboff 2012-10-04 09:44:35 PDT
(In reply to comment #3)
> (From update of attachment 166981 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=166981&action=review
> 
> > Source/WTF/wtf/text/WTFString.cpp:281
> >      if (static_cast<unsigned>(lengthToRemove) > length() - position)
> >          lengthToRemove = length() - position;
> 
> No idea if that case is common.
> If it is, shouldn't we just return a substring sharing impl here?

From what I've seen, the use of remove is within length range and this wouldn't help.

> > Source/WTF/wtf/text/WTFString.cpp:289
> > +        RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(length() - lengthToRemove, data);
> > +        memcpy(data, characters8(), position * sizeof(LChar));
> > +        memcpy(data + position, characters8() + position + lengthToRemove,
> > +            (length() - lengthToRemove - position) * sizeof(LChar));
> > +        m_impl = newImpl.release();
> 
> I would do an inline template with that code taking CharacterType as argument.

Done.
Comment 5 Michael Saboff 2012-10-04 09:45:17 PDT
Committed r130404: <http://trac.webkit.org/changeset/130404>