Bug 98299

Summary: String::remove will convert an 8 bit string to a 16 bit string
Product: WebKit Reporter: Michael Saboff <msaboff>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch benjamin: review+

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>