Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
1b1b4841
Commit
1b1b4841
authored
15 years ago
by
hjk
Browse files
Options
Downloads
Patches
Plain Diff
qstringbuilder: final version to merge into Qt proper
parent
10a2274b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libs/utils/qstringbuilder.h
+17
-23
17 additions, 23 deletions
src/libs/utils/qstringbuilder.h
tests/benchmarks/qstringbuilder/main.cpp
+2
-2
2 additions, 2 deletions
tests/benchmarks/qstringbuilder/main.cpp
with
19 additions
and
25 deletions
src/libs/utils/qstringbuilder.h
+
17
−
23
View file @
1b1b4841
...
...
@@ -53,10 +53,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE
(
Core
)
// Using this relies on changing the QString::QString(QChar *, int)
// constructor to allocated an unitialized string of the given size.
//#define USE_CHANGED_QSTRING 1
class
QLatin1Literal
{
public:
...
...
@@ -74,35 +70,33 @@ private:
namespace
{
template
<
typename
T
>
class
QConcatenable
{};
template
<
typename
A
,
typename
B
>
class
QStringBuilder
{
public:
QStringBuilder
(
const
A
&
a_
,
const
B
&
b_
)
:
a
(
a_
),
b
(
b_
)
{}
operator
QString
()
const
;
public
:
operator
QString
()
const
{
#if 0
QString s(QConcatenable< QStringBuilder<A, B> >::size(*this),
QString::Uninitialized())
;
#else
QString
s
;
s
.
resize
(
QConcatenable
<
QStringBuilder
<
A
,
B
>
>::
size
(
*
this
));
#endif
QChar
*
d
=
s
.
data
();
QConcatenable
<
QStringBuilder
<
A
,
B
>
>::
appendTo
(
*
this
,
d
);
return
s
;
}
const
A
&
a
;
const
B
&
b
;
};
// make sure the operator% defined below acts only on types we want to handle.
template
<
typename
T
>
struct
QConcatenable
{};
template
<
typename
A
,
typename
B
>
QStringBuilder
<
A
,
B
>::
operator
QString
()
const
{
#ifdef USE_CHANGED_QSTRING
QString
s
(
this
->
size
(),
QChar
(
-
1
));
#else
QString
s
;
s
.
resize
(
QConcatenable
<
QStringBuilder
<
A
,
B
>
>::
size
(
*
this
));
#endif
QChar
*
d
=
s
.
data
();
QConcatenable
<
QStringBuilder
<
A
,
B
>
>::
appendTo
(
*
this
,
d
);
return
s
;
}
template
<
>
struct
QConcatenable
<
char
>
{
...
...
This diff is collapsed.
Click to expand it.
tests/benchmarks/qstringbuilder/main.cpp
+
2
−
2
View file @
1b1b4841
...
...
@@ -275,8 +275,8 @@ private:
int
main
(
int
argc
,
char
*
argv
[])
{
42
%
3
;
// Sanity test, should always work.
//qDebug() << (QString("xx") * QLatin1String("y")).toString();
//42 % 3; // Sanity test, should always work.
//QString("x") % 2; // Sanity test, should only compile when the
// operator%(QString, int) is visible.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment