Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
http-server
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
1
Merge Requests
1
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
cython-plus
http-server
Commits
51847a21
Commit
51847a21
authored
Nov 25, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement GIL-free string formatting
parent
21f67d41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
src/stdlib/format.pxd
src/stdlib/format.pxd
+33
-0
src/stdlib/string.pxd
src/stdlib/string.pxd
+4
-1
No files found.
src/stdlib/format.pxd
0 → 100644
View file @
51847a21
from
stdlib.string
cimport
Str
cdef
extern
from
*
nogil
:
"""
#include <fmt/format.h>
#include <string_view>
template <typename T, typename S>
struct Cy_Str_Adapter {
using type = T;
constexpr static auto adapt(T t) { return t; }
};
template <typename T>
struct Cy_Str_Adapter<T*, T> {
using type = std::string_view;
static std::string_view adapt(T* t) {
return t->operator std::string_view();
}
};
template <typename S, typename... T>
S * format(fmt::format_string<typename Cy_Str_Adapter<T, S>::type...> fmt, T... args) {
S *s = new S();
s->_str = fmt::format(fmt, Cy_Str_Adapter<T, S>::adapt(args)...);
return s;
}
"""
Str
format
"format<Cy_Str>"
(
const
char
*
,
...)
except
+
src/stdlib/string.pxd
View file @
51847a21
...
...
@@ -22,7 +22,7 @@ cdef extern from "<cctype>" namespace "std" nogil:
cdef
cypclass
Str
:
cdef
cypclass
Str
"Cy_Str"
:
string
_str
__init__
(
self
,
const
char
*
s
):
...
...
@@ -137,6 +137,9 @@ cdef cypclass Str:
int
__int__
(
self
)
except
+
:
return
stoi
(
self
.
_str
)
string_view
__string_view__
(
self
):
return
string_view
(
self
.
_str
.
data
(),
self
.
_str
.
size
())
@
staticmethod
const
char
*
to_c_str
(
Str
s
):
if
s
is
NULL
:
...
...
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