Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cython-based speedup for websocket mask function.
This optimization is currently activated only if Cython is present when Tornado is installed.
- Loading branch information
Showing
6 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- python -*- | ||
from cpython.mem cimport PyMem_Malloc, PyMem_Free | ||
|
||
def websocket_mask(bytes mask_bytes, bytes data_bytes): | ||
cdef size_t data_len = len(data_bytes) | ||
cdef char* data = data_bytes | ||
cdef char* mask = mask_bytes | ||
cdef size_t i | ||
cdef char* buf = <char*> PyMem_Malloc(data_len) | ||
try: | ||
for i in xrange(data_len): | ||
buf[i] = data[i] ^ mask[i % 4] | ||
# Is there a zero-copy equivalent of this? | ||
return <bytes>(buf[:data_len]) | ||
finally: | ||
PyMem_Free(buf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters