Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Libraries
fmt
Commits
fe00cddd
Commit
fe00cddd
authored
Aug 25, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move part counter to the namespace scope
to reduce the number of instantiations
parent
1a7d172d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
39 deletions
+34
-39
include/fmt/compile.h
include/fmt/compile.h
+34
-39
No files found.
include/fmt/compile.h
View file @
fe00cddd
...
@@ -260,57 +260,52 @@ class prepared_format {
...
@@ -260,57 +260,52 @@ class prepared_format {
PreparedPartsProvider
parts_provider_
;
PreparedPartsProvider
parts_provider_
;
};
};
template
<
typename
Format
>
class
compiletime_prepared_parts_type_provider
{
template
<
typename
Char
>
struct
part_counter
{
private:
public:
using
char_type
=
char_t
<
Format
>
;
FMT_CONSTEXPR
part_counter
()
:
counter_
(
0u
)
{}
class
count_handler
{
public:
FMT_CONSTEXPR
count_handler
()
:
counter_
(
0u
)
{}
FMT_CONSTEXPR
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
FMT_CONSTEXPR
void
on_text
(
const
Char
*
begin
,
const
Char
*
end
)
{
if
(
begin
!=
end
)
++
counter_
;
if
(
begin
!=
end
)
++
counter_
;
}
}
FMT_CONSTEXPR
void
on_arg_id
()
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_arg_id
()
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_arg_id
(
unsigned
)
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_arg_id
(
unsigned
)
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_arg_id
(
basic_string_view
<
char_type
>
)
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_arg_id
(
basic_string_view
<
Char
>
)
{
++
counter_
;
}
FMT_CONSTEXPR
void
on_replacement_field
(
const
char_type
*
)
{}
FMT_CONSTEXPR
void
on_replacement_field
(
const
Char
*
)
{}
FMT_CONSTEXPR
const
char_type
*
on_format_specs
(
const
char_type
*
begin
,
FMT_CONSTEXPR
const
Char
*
on_format_specs
(
const
Char
*
begin
,
const
char_type
*
end
)
{
const
Char
*
end
)
{
return
find_matching_brace
(
begin
,
end
);
// Find the matching brace.
unsigned
braces_counter
=
0
;
for
(;
begin
!=
end
;
++
begin
)
{
if
(
*
begin
==
'{'
)
{
++
braces_counter
;
}
else
if
(
*
begin
==
'}'
)
{
if
(
braces_counter
==
0u
)
break
;
--
braces_counter
;
}
}
}
return
begin
;
}
FMT_CONSTEXPR
void
on_error
(
const
char
*
)
{}
FMT_CONSTEXPR
void
on_error
(
const
char
*
)
{}
FMT_CONSTEXPR
unsigned
result
()
const
{
return
counter_
;
}
FMT_CONSTEXPR
unsigned
result
()
const
{
return
counter_
;
}
private:
private:
FMT_CONSTEXPR
const
char_type
*
find_matching_brace
(
const
char_type
*
begin
,
unsigned
counter_
;
const
char_type
*
end
)
{
};
unsigned
braces_counter
{
0u
};
for
(;
begin
!=
end
;
++
begin
)
{
if
(
*
begin
==
'{'
)
{
++
braces_counter
;
}
else
if
(
*
begin
==
'}'
)
{
if
(
braces_counter
==
0u
)
break
;
--
braces_counter
;
}
}
return
begin
;
}
private:
template
<
typename
Format
>
class
compiletime_prepared_parts_type_provider
{
unsigned
counter_
;
private:
}
;
using
char_type
=
char_t
<
Format
>
;
static
FMT_CONSTEXPR
unsigned
count_parts
()
{
static
FMT_CONSTEXPR
unsigned
count_parts
()
{
FMT_CONSTEXPR_DECL
const
auto
text
=
to_string_view
(
Format
{});
FMT_CONSTEXPR_DECL
const
auto
text
=
to_string_view
(
Format
{});
count_handler
handl
er
;
part_counter
<
char_type
>
count
er
;
internal
::
parse_format_string
<
/*IS_CONSTEXPR=*/
true
>
(
text
,
handl
er
);
internal
::
parse_format_string
<
/*IS_CONSTEXPR=*/
true
>
(
text
,
count
er
);
return
handl
er
.
result
();
return
count
er
.
result
();
}
}
// Workaround for old compilers. Compiletime parts preparation will not be
// Workaround for old compilers. Compiletime parts preparation will not be
...
...
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