Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
c50c4367
Commit
c50c4367
authored
Jan 13, 2014
by
Rafaël Carré
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contrib: taglib: fetch patch from
https://github.com/taglib/taglib/pull/309
Closes: #10227
parent
1e335d5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
0 deletions
+132
-0
contrib/src/taglib/0002-Rewrote-ByteVector-replace-simpler.patch
.../src/taglib/0002-Rewrote-ByteVector-replace-simpler.patch
+131
-0
contrib/src/taglib/rules.mak
contrib/src/taglib/rules.mak
+1
-0
No files found.
contrib/src/taglib/0002-Rewrote-ByteVector-replace-simpler.patch
0 → 100644
View file @
c50c4367
From 4a7d31c87bf41c1de21cb725176d5b34c2a95720 Mon Sep 17 00:00:00 2001
From: Tsuda Kageyu <tsuda.kageyu@gmail.com>
Date: Thu, 14 Nov 2013 14:05:32 +0900
Subject: [PATCH 2/3] Rewrote ByteVector::replace() simpler
---
taglib/toolkit/tbytevector.cpp | 77 +++++++++++++++---------------------------
tests/test_bytevector.cpp | 5 +++
2 files changed, 33 insertions(+), 49 deletions(-)
diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp
index b658246..566a20f 100644
--- a/taglib/toolkit/tbytevector.cpp
+++ b/taglib/toolkit/tbytevector.cpp
@@ -31,6 +31,7 @@
#include <iostream>
#include <cstdio>
#include <cstring>
+#include <cstddef>
#include <tstring.h>
#include <tdebug.h>
@@ -508,62 +509,40 @@
ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit
if(pattern.size() == 0 || pattern.size() > size())
return *this;
- const uint withSize = with.size();
- const uint patternSize = pattern.size();
- int offset = 0;
+ const size_t withSize = with.size();
+ const size_t patternSize = pattern.size();
+ const ptrdiff_t diff = withSize - patternSize;
+
+ size_t offset = 0;
+ while (true)
+ {
+ offset = find(pattern, offset);
+ if(offset == static_cast<size_t>(-1)) // Use npos in taglib2.
+ break;
- if(withSize == patternSize) {
- // 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) {
- if(offset == 0)
- // pattern not found, do nothing:
- return *this;
- newSize += size() - offset;
- break;
+ if(diff < 0) {
+ ::memmove(
+ data() + offset + withSize,
+ data() + offset + patternSize,
+ size() - offset - patternSize);
+ resize(size() + diff);
}
- newSize += (next - offset) + withSize;
- offset = next + patternSize;
- }
-
- // new private data of appropriate size:
- ByteVectorPrivate *newData = new ByteVectorPrivate(newSize, 0);
- char *target = DATA(newData);
- const char *source = data();
-
- // copy modified data into new private data:
- offset = 0;
- for(;;) {
- int next = find(pattern, offset);
- if(next < 0) {
- ::memcpy(target, source + offset, size() - offset);
- break;
+ else if(diff > 0) {
+ resize(size() + diff);
+ ::memmove(
+ data() + offset + withSize,
+ data() + offset + patternSize,
+ size() - diff - offset - patternSize);
}
- int chunkSize = next - offset;
- ::memcpy(target, source + offset, chunkSize);
- target += chunkSize;
- ::memcpy(target, with.data(), withSize);
- target += withSize;
- offset += chunkSize + patternSize;
- }
- // replace private data:
- if(d->deref())
- delete d;
+ ::memcpy(data() + offset, with.data(), with.size());
- d = newData;
+ offset += withSize;
+ if(offset > size() - patternSize)
+ break;
+ }
return *this;
}
diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp
index 9efd23a..eca74f8 100644
--- a/tests/test_bytevector.cpp
+++ b/tests/test_bytevector.cpp
@@ -239,6 +239,11 @@
public:
a.replace(ByteVector("ab"), ByteVector());
CPPUNIT_ASSERT_EQUAL(ByteVector("cdf"), a);
}
+ {
+ ByteVector a("abcdabf");
+ a.replace(ByteVector("bf"), ByteVector("x"));
+ CPPUNIT_ASSERT_EQUAL(ByteVector("abcdax"), a);
+ }
}
};
--
1.8.5.2
contrib/src/taglib/rules.mak
View file @
c50c4367
...
...
@@ -13,6 +13,7 @@ $(TARBALLS)/taglib-$(TAGLIB_VERSION).tar.gz:
taglib
:
taglib-$(TAGLIB_VERSION).tar.gz .sum-taglib
$(UNPACK)
$(APPLY)
$(SRC)
/taglib/taglib-pc.patch
$(APPLY)
$(SRC)
/taglib/0002-Rewrote-ByteVector-replace-simpler.patch
$(MOVE)
.taglib
:
taglib toolchain.cmake
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment