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+

Michael Saboff
Reported 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.
Attachments
Patch (1.92 KB, patch)
2012-10-03 16:00 PDT, Michael Saboff
benjamin: review+
Michael Saboff
Comment 1 2012-10-03 14:19:41 PDT
The remove method is actually in WTFString.cpp (String::remove).
Michael Saboff
Comment 2 2012-10-03 16:00:05 PDT
Benjamin Poulain
Comment 3 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.
Michael Saboff
Comment 4 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.
Michael Saboff
Comment 5 2012-10-04 09:45:17 PDT
Note You need to log in before you can comment on or make changes to this bug.