mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
ByteVector::replace: forgot detach() and opt. when pattern not found
This commit is contained in:
parent
ad7645f8e9
commit
3b14dc3e94
@ -436,25 +436,29 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit
|
||||
int offset = 0;
|
||||
|
||||
if(withSize == patternSize) {
|
||||
// I think this case might be common enough to optimize it
|
||||
offset = find(pattern);
|
||||
while(offset >= 0) {
|
||||
::memcpy(data() + offset, with.data(), withSize);
|
||||
offset = find(pattern, offset + withSize);
|
||||
}
|
||||
return *this;
|
||||
// I think this case might be common enough to optimize it
|
||||
detach();
|
||||
offset = find(pattern);
|
||||
while(offset >= 0) {
|
||||
::memcpy(data() + offset, with.data(), withSize);
|
||||
offset = find(pattern, offset + withSize);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// calculate new size:
|
||||
uint newSize = 0;
|
||||
for(;;) {
|
||||
int next = find(pattern, offset);
|
||||
if(next < 0) {
|
||||
newSize += size() - offset;
|
||||
break;
|
||||
}
|
||||
newSize += (next - offset) + withSize;
|
||||
offset = next + patternSize;
|
||||
int next = find(pattern, offset);
|
||||
if(next < 0) {
|
||||
if(offset == 0)
|
||||
// pattern not found, do nothing:
|
||||
return *this;
|
||||
newSize += size() - offset;
|
||||
break;
|
||||
}
|
||||
newSize += (next - offset) + withSize;
|
||||
offset = next + patternSize;
|
||||
}
|
||||
|
||||
// new private data of appropriate size:
|
||||
@ -467,8 +471,8 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit
|
||||
for(;;) {
|
||||
int next = find(pattern, offset);
|
||||
if(next < 0) {
|
||||
::memcpy(target, source + offset, size() - offset);
|
||||
break;
|
||||
::memcpy(target, source + offset, size() - offset);
|
||||
break;
|
||||
}
|
||||
int chunkSize = next - offset;
|
||||
::memcpy(target, source + offset, chunkSize);
|
||||
|
Loading…
x
Reference in New Issue
Block a user