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
e1e1bfbf
Commit
e1e1bfbf
authored
15 years ago
by
hjk
Browse files
Options
Downloads
Patches
Plain Diff
qtringbuilder: simplify by removing the QStringBuilder<QString> specialization
parent
ea6617ce
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libs/utils/qstringbuilder.h
+34
-49
34 additions, 49 deletions
src/libs/utils/qstringbuilder.h
tests/benchmarks/qstringbuilder/main.cpp
+3
-3
3 additions, 3 deletions
tests/benchmarks/qstringbuilder/main.cpp
with
37 additions
and
52 deletions
src/libs/utils/qstringbuilder.h
+
34
−
49
View file @
e1e1bfbf
...
...
@@ -88,10 +88,17 @@ private:
template
<
typename
A
,
typename
B
>
class
QStringBuilderPair
;
class
QStringBuilderPair
{
public:
QStringBuilderPair
(
const
A
&
a_
,
const
B
&
b_
)
:
a
(
a_
),
b
(
b_
)
{}
template
<
typename
A
,
typename
B
>
inline
int
qStringBuilderSize
(
const
QStringBuilderPair
<
A
,
B
>
&
p
);
const
A
&
a
;
const
B
&
b
;
};
namespace
Qt
{
inline
int
qStringBuilderSize
(
const
char
)
{
return
1
;
}
...
...
@@ -105,13 +112,22 @@ inline int qStringBuilderSize(const QString &a) { return a.size(); }
inline
int
qStringBuilderSize
(
const
QStringRef
&
a
)
{
return
a
.
size
();
}
template
<
typename
A
,
typename
B
>
inline
void
qStringBuilderAppend
(
const
QStringBuilderPair
<
A
,
B
>
&
p
,
QChar
*&
out
);
inline
int
qStringBuilderSize
(
const
QStringBuilderPair
<
A
,
B
>
&
p
)
{
return
qStringBuilderSize
(
p
.
a
)
+
qStringBuilderSize
(
p
.
b
);
}
inline
void
qStringBuilderAppend
(
const
char
c
,
QChar
*&
out
)
{
*
out
++
=
QLatin1Char
(
c
);
}
inline
void
qStringBuilderAppend
(
const
QLatin1Char
c
,
QChar
*&
out
)
{
*
out
++
=
c
;
}
inline
void
qStringBuilderAppend
(
const
char
c
,
QChar
*&
out
)
{
*
out
++
=
QLatin1Char
(
c
);
}
inline
void
qStringBuilderAppend
(
const
QLatin1Char
c
,
QChar
*&
out
)
{
*
out
++
=
c
;
}
inline
void
qStringBuilderAppend
(
const
QLatin1String
&
a
,
QChar
*&
out
)
{
...
...
@@ -139,6 +155,15 @@ inline void qStringBuilderAppend(const QLatin1Literal &a, QChar *&out)
*
out
++
=
QLatin1Char
(
*
s
++
);
}
template
<
typename
A
,
typename
B
>
inline
void
qStringBuilderAppend
(
const
QStringBuilderPair
<
A
,
B
>
&
p
,
QChar
*&
out
)
{
qStringBuilderAppend
(
p
.
a
,
out
);
qStringBuilderAppend
(
p
.
b
,
out
);
}
}
// Qt
template
<
typename
A
>
class
QStringBuilder
:
public
A
...
...
@@ -152,43 +177,15 @@ public:
QString
s
(
this
->
size
(),
QChar
(
-
1
));
#else
QString
s
;
s
.
resize
(
this
->
size
(
));
s
.
resize
(
Qt
::
qStringBuilderSize
(
*
this
));
#endif
QChar
*
d
=
s
.
data
();
qStringBuilderAppend
(
*
this
,
d
);
Qt
::
qStringBuilderAppend
(
*
this
,
d
);
return
s
;
}
};
template
<
>
class
QStringBuilder
<
QString
>
{
public:
QStringBuilder
(
const
QString
&
a_
)
:
a
(
&
a_
)
{}
inline
operator
QString
()
const
{
return
*
a
;
}
private
:
const
QString
*
a
;
};
template
<
typename
A
,
typename
B
>
class
QStringBuilderPair
{
public:
QStringBuilderPair
(
const
A
&
a_
,
const
B
&
b_
)
:
a
(
a_
),
b
(
b_
)
{}
inline
int
size
()
const
{
return
qStringBuilderSize
(
a
)
+
qStringBuilderSize
(
b
);
}
//private:
const
A
&
a
;
const
B
&
b
;
};
template
<
typename
A
,
typename
B
>
QStringBuilder
<
QStringBuilderPair
<
A
,
B
>
>
...
...
@@ -197,18 +194,6 @@ operator%(const A &a, const B &b)
return
QStringBuilderPair
<
A
,
B
>
(
a
,
b
);
}
template
<
typename
A
,
typename
B
>
inline
void
qStringBuilderAppend
(
const
QStringBuilderPair
<
A
,
B
>
&
p
,
QChar
*&
out
)
{
qStringBuilderAppend
(
p
.
a
,
out
);
qStringBuilderAppend
(
p
.
b
,
out
);
}
template
<
typename
A
,
typename
B
>
inline
int
qStringBuilderSize
(
const
QStringBuilderPair
<
A
,
B
>
&
p
)
{
return
qStringBuilderSize
(
p
.
a
)
+
qStringBuilderSize
(
p
.
b
);
}
QT_END_NAMESPACE
...
...
This diff is collapsed.
Click to expand it.
tests/benchmarks/qstringbuilder/main.cpp
+
3
−
3
View file @
e1e1bfbf
...
...
@@ -124,11 +124,11 @@ private slots:
}
void
b_string_l1string
()
{
QBENCHMARK
{
r
=
string
%
l1string
;
}
COMPARE
(
r
,
string
+
l1
literal
);
COMPARE
(
r
,
string
+
l1
string
);
}
void
s_string_l1literal
()
{
QBENCHMARK
{
r
=
string
+
l1
literal
;
}
COMPARE
(
r
,
QString
(
string
%
l1
string
));
QBENCHMARK
{
r
=
string
+
l1
string
;
}
COMPARE
(
r
,
QString
(
string
%
l1
literal
));
}
void
s_string_l1string
()
{
QBENCHMARK
{
r
=
string
+
l1string
;
}
...
...
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