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
28303e86
Commit
28303e86
authored
15 years ago
by
hjk
Browse files
Options
Downloads
Patches
Plain Diff
qstringbuilder: a version without QLatin1Literal
parent
efc0b208
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
+32
-37
32 additions, 37 deletions
src/libs/utils/qstringbuilder.h
tests/benchmarks/qstringbuilder/main.cpp
+13
-12
13 additions, 12 deletions
tests/benchmarks/qstringbuilder/main.cpp
with
45 additions
and
49 deletions
src/libs/utils/qstringbuilder.h
+
32
−
37
View file @
28303e86
...
@@ -57,23 +57,10 @@ QT_MODULE(Core)
...
@@ -57,23 +57,10 @@ QT_MODULE(Core)
// constructor to allocated an unitialized string of the given size.
// constructor to allocated an unitialized string of the given size.
//#define USE_CHANGED_QSTRING 1
//#define USE_CHANGED_QSTRING 1
class
QLatin1Literal
{
public:
template
<
int
N
>
QLatin1Literal
(
const
char
(
&
str
)[
N
])
:
m_size
(
N
-
1
),
m_data
(
str
)
{}
inline
int
size
()
const
{
return
m_size
;
}
inline
const
char
*
data
()
const
{
return
m_data
;
}
private
:
const
int
m_size
;
const
char
*
m_data
;
};
namespace
{
namespace
{
template
<
typename
T
>
struct
QConcatenable
{};
template
<
typename
A
,
typename
B
>
template
<
typename
A
,
typename
B
>
class
QStringBuilder
class
QStringBuilder
{
{
...
@@ -86,10 +73,6 @@ public:
...
@@ -86,10 +73,6 @@ public:
const
B
&
b
;
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
>
template
<
typename
A
,
typename
B
>
QStringBuilder
<
A
,
B
>::
operator
QString
()
const
QStringBuilder
<
A
,
B
>::
operator
QString
()
const
{
{
...
@@ -107,7 +90,7 @@ QStringBuilder<A, B>::operator QString() const
...
@@ -107,7 +90,7 @@ QStringBuilder<A, B>::operator QString() const
template
<
>
struct
QConcatenable
<
char
>
template
<
>
struct
QConcatenable
<
char
>
{
{
typedef
char
type
;
typedef
char
type
;
static
int
size
(
const
char
)
{
return
1
;
}
static
inline
int
size
(
const
char
)
{
return
1
;
}
static
inline
void
appendTo
(
const
char
c
,
QChar
*&
out
)
static
inline
void
appendTo
(
const
char
c
,
QChar
*&
out
)
{
{
*
out
++
=
QLatin1Char
(
c
);
*
out
++
=
QLatin1Char
(
c
);
...
@@ -117,7 +100,7 @@ template <> struct QConcatenable<char>
...
@@ -117,7 +100,7 @@ template <> struct QConcatenable<char>
template
<
>
struct
QConcatenable
<
QLatin1Char
>
template
<
>
struct
QConcatenable
<
QLatin1Char
>
{
{
typedef
QLatin1Char
type
;
typedef
QLatin1Char
type
;
static
int
size
(
const
QLatin1Char
)
{
return
1
;
}
static
inline
int
size
(
const
QLatin1Char
)
{
return
1
;
}
static
inline
void
appendTo
(
const
QLatin1Char
c
,
QChar
*&
out
)
static
inline
void
appendTo
(
const
QLatin1Char
c
,
QChar
*&
out
)
{
{
*
out
++
=
c
;
*
out
++
=
c
;
...
@@ -127,7 +110,7 @@ template <> struct QConcatenable<QLatin1Char>
...
@@ -127,7 +110,7 @@ template <> struct QConcatenable<QLatin1Char>
template
<
>
struct
QConcatenable
<
QLatin1String
>
template
<
>
struct
QConcatenable
<
QLatin1String
>
{
{
typedef
QLatin1String
type
;
typedef
QLatin1String
type
;
static
int
size
(
const
QLatin1String
&
a
)
{
return
qstrlen
(
a
.
latin1
());
}
static
inline
int
size
(
const
QLatin1String
&
a
)
{
return
qstrlen
(
a
.
latin1
());
}
static
inline
void
appendTo
(
const
QLatin1String
&
a
,
QChar
*&
out
)
static
inline
void
appendTo
(
const
QLatin1String
&
a
,
QChar
*&
out
)
{
{
for
(
const
char
*
s
=
a
.
latin1
();
*
s
;
)
for
(
const
char
*
s
=
a
.
latin1
();
*
s
;
)
...
@@ -136,21 +119,10 @@ template <> struct QConcatenable<QLatin1String>
...
@@ -136,21 +119,10 @@ template <> struct QConcatenable<QLatin1String>
};
};
template
<
>
struct
QConcatenable
<
QLatin1Literal
>
{
typedef
QLatin1Literal
type
;
static
int
size
(
const
QLatin1Literal
&
a
)
{
return
a
.
size
();
}
static
inline
void
appendTo
(
const
QLatin1Literal
&
a
,
QChar
*&
out
)
{
for
(
const
char
*
s
=
a
.
data
();
*
s
;
)
*
out
++
=
QLatin1Char
(
*
s
++
);
}
};
template
<
>
struct
QConcatenable
<
QString
>
template
<
>
struct
QConcatenable
<
QString
>
{
{
typedef
QString
type
;
typedef
QString
type
;
static
int
size
(
const
QString
&
a
)
{
return
a
.
size
();
}
static
inline
int
size
(
const
QString
&
a
)
{
return
a
.
size
();
}
static
inline
void
appendTo
(
const
QString
&
a
,
QChar
*&
out
)
static
inline
void
appendTo
(
const
QString
&
a
,
QChar
*&
out
)
{
{
const
int
n
=
a
.
size
();
const
int
n
=
a
.
size
();
...
@@ -162,7 +134,7 @@ template <> struct QConcatenable<QString>
...
@@ -162,7 +134,7 @@ template <> struct QConcatenable<QString>
template
<
>
struct
QConcatenable
<
QStringRef
>
template
<
>
struct
QConcatenable
<
QStringRef
>
{
{
typedef
QStringRef
type
;
typedef
QStringRef
type
;
static
int
size
(
const
QStringRef
&
a
)
{
return
a
.
size
();
}
static
inline
int
size
(
const
QStringRef
&
a
)
{
return
a
.
size
();
}
static
inline
void
appendTo
(
QStringRef
a
,
QChar
*&
out
)
static
inline
void
appendTo
(
QStringRef
a
,
QChar
*&
out
)
{
{
const
int
n
=
a
.
size
();
const
int
n
=
a
.
size
();
...
@@ -171,12 +143,36 @@ template <> struct QConcatenable<QStringRef>
...
@@ -171,12 +143,36 @@ template <> struct QConcatenable<QStringRef>
}
}
};
};
template
<
int
N
>
struct
QConcatenable
<
const
char
[
N
]
>
{
typedef
const
char
type
[
N
];
static
inline
int
size
(
const
char
*
)
{
return
N
-
1
;
}
static
inline
void
appendTo
(
const
char
*
a
,
QChar
*&
out
)
{
for
(
int
i
=
0
;
i
<
N
-
1
;
++
i
)
*
out
++
=
QLatin1Char
(
*
a
++
);
}
};
template
<
int
N
>
struct
QConcatenable
<
char
[
N
]
>
{
typedef
char
type
[
N
];
static
inline
int
size
(
const
char
*
)
{
return
N
-
1
;
}
static
inline
void
appendTo
(
const
char
*
a
,
QChar
*&
out
)
{
for
(
int
i
=
0
;
i
<
N
-
1
;
++
i
)
*
out
++
=
QLatin1Char
(
*
a
++
);
}
};
template
<
typename
A
,
typename
B
>
template
<
typename
A
,
typename
B
>
struct
QConcatenable
<
QStringBuilder
<
A
,
B
>
>
struct
QConcatenable
<
QStringBuilder
<
A
,
B
>
>
{
{
typedef
QStringBuilder
<
A
,
B
>
type
;
typedef
QStringBuilder
<
A
,
B
>
type
;
static
int
size
(
const
type
&
p
)
static
inline
int
size
(
const
type
&
p
)
{
{
return
QConcatenable
<
A
>::
size
(
p
.
a
)
+
QConcatenable
<
B
>::
size
(
p
.
b
);
return
QConcatenable
<
A
>::
size
(
p
.
a
)
+
QConcatenable
<
B
>::
size
(
p
.
b
);
}
}
...
@@ -198,7 +194,6 @@ QStringBuilder<A, B> operator%(const A &a, const B &b)
...
@@ -198,7 +194,6 @@ QStringBuilder<A, B> operator%(const A &a, const B &b)
return
QStringBuilder
<
A1
,
B1
>
(
a
,
b
);
return
QStringBuilder
<
A1
,
B1
>
(
a
,
b
);
}
}
QT_END_NAMESPACE
QT_END_NAMESPACE
QT_END_HEADER
QT_END_HEADER
...
...
This diff is collapsed.
Click to expand it.
tests/benchmarks/qstringbuilder/main.cpp
+
13
−
12
View file @
28303e86
...
@@ -13,15 +13,17 @@
...
@@ -13,15 +13,17 @@
#define SEP(s) qDebug() << "\n\n-------- " s " ---------";
#define SEP(s) qDebug() << "\n\n-------- " s " ---------";
#define L(s) QLatin1String(s)
#define L(s) QLatin1String(s)
const
char
l1literal
[]
=
"some string literal"
;
class
tst_qstringbuilder
:
public
QObject
class
tst_qstringbuilder
:
public
QObject
{
{
Q_OBJECT
Q_OBJECT
public:
public:
tst_qstringbuilder
()
tst_qstringbuilder
()
:
l1literal
(
"some string literal"
),
:
l1string
(
"some string
literal
"
),
l1string
(
l1
literal
),
ba
(
"some string
literal
"
),
ba
(
l1
literal
),
string
(
l1string
),
string
(
l1string
),
stringref
(
&
string
,
2
,
10
),
stringref
(
&
string
,
2
,
10
),
achar
(
'c'
)
achar
(
'c'
)
...
@@ -71,12 +73,12 @@ private slots:
...
@@ -71,12 +73,12 @@ private slots:
void
separator_1
()
{
SEP
(
"literal + literal (builder first)"
);
}
void
separator_1
()
{
SEP
(
"literal + literal (builder first)"
);
}
void
b_2_l1literal
()
{
void
b_2_l1literal
()
{
QBENCHMARK
{
r
=
l1
literal
%
l1literal
;
}
QBENCHMARK
{
r
=
l1
string
%
l1literal
;
}
COMPARE
(
r
,
l1string
+
l1string
);
COMPARE
(
r
,
l1string
+
l1string
);
}
}
void
s_2_l1string
()
{
void
s_2_l1string
()
{
QBENCHMARK
{
r
=
l1string
+
l1string
;
}
QBENCHMARK
{
r
=
l1string
+
l1string
;
}
COMPARE
(
r
,
QString
(
l1
literal
%
l1literal
));
COMPARE
(
r
,
QString
(
l1
string
%
l1literal
));
}
}
...
@@ -139,37 +141,37 @@ private slots:
...
@@ -139,37 +141,37 @@ private slots:
void
separator_3
()
{
SEP
(
"3 literals"
);
}
void
separator_3
()
{
SEP
(
"3 literals"
);
}
void
b_3_l1literal
()
{
void
b_3_l1literal
()
{
QBENCHMARK
{
r
=
l1
literal
%
l1literal
%
l1literal
;
}
QBENCHMARK
{
r
=
l1
string
%
l1literal
%
l1literal
;
}
COMPARE
(
r
,
l1string
+
l1string
+
l1string
);
COMPARE
(
r
,
l1string
+
l1string
+
l1string
);
}
}
void
s_3_l1string
()
{
void
s_3_l1string
()
{
QBENCHMARK
{
r
=
l1string
+
l1string
+
l1string
;
}
QBENCHMARK
{
r
=
l1string
+
l1string
+
l1string
;
}
COMPARE
(
r
,
QString
(
l1
literal
%
l1literal
%
l1literal
));
COMPARE
(
r
,
QString
(
l1
string
%
l1literal
%
l1literal
));
}
}
void
separator_4
()
{
SEP
(
"4 literals"
);
}
void
separator_4
()
{
SEP
(
"4 literals"
);
}
void
b_4_l1literal
()
{
void
b_4_l1literal
()
{
QBENCHMARK
{
r
=
l1
literal
%
l1literal
%
l1literal
%
l1literal
;
}
QBENCHMARK
{
r
=
l1
string
%
l1literal
%
l1literal
%
l1literal
;
}
COMPARE
(
r
,
l1string
+
l1string
+
l1string
+
l1string
);
COMPARE
(
r
,
l1string
+
l1string
+
l1string
+
l1string
);
}
}
void
s_4_l1string
()
{
void
s_4_l1string
()
{
QBENCHMARK
{
r
=
l1string
+
l1string
+
l1string
+
l1string
;
}
QBENCHMARK
{
r
=
l1string
+
l1string
+
l1string
+
l1string
;
}
COMPARE
(
r
,
QString
(
l1
literal
%
l1literal
%
l1literal
%
l1literal
));
COMPARE
(
r
,
QString
(
l1
string
%
l1literal
%
l1literal
%
l1literal
));
}
}
void
separator_5
()
{
SEP
(
"5 literals"
);
}
void
separator_5
()
{
SEP
(
"5 literals"
);
}
void
b_5_l1literal
()
{
void
b_5_l1literal
()
{
QBENCHMARK
{
r
=
l1
literal
%
l1literal
%
l1literal
%
l1literal
%
l1literal
;
}
QBENCHMARK
{
r
=
l1
string
%
l1literal
%
l1literal
%
l1literal
%
l1literal
;
}
COMPARE
(
r
,
l1string
+
l1string
+
l1string
+
l1string
+
l1string
);
COMPARE
(
r
,
l1string
+
l1string
+
l1string
+
l1string
+
l1string
);
}
}
void
s_5_l1string
()
{
void
s_5_l1string
()
{
QBENCHMARK
{
r
=
l1string
+
l1string
+
l1string
+
l1string
+
l1string
;
}
QBENCHMARK
{
r
=
l1string
+
l1string
+
l1string
+
l1string
+
l1string
;
}
COMPARE
(
r
,
QString
(
l1
literal
%
l1literal
%
l1literal
%
l1literal
%
l1literal
));
COMPARE
(
r
,
QString
(
l1
string
%
l1literal
%
l1literal
%
l1literal
%
l1literal
));
}
}
...
@@ -260,7 +262,6 @@ private slots:
...
@@ -260,7 +262,6 @@ private slots:
}
}
private
:
private
:
const
QLatin1Literal
l1literal
;
const
QLatin1String
l1string
;
const
QLatin1String
l1string
;
const
QByteArray
ba
;
const
QByteArray
ba
;
const
QString
string
;
const
QString
string
;
...
...
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