mercurial/cffi/mpatchbuild.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 16 Oct 2019 17:49:30 +0200
changeset 43254 181d28ba05da
parent 43077 687b865b95ad
child 43668 53607fd3ec6c
permissions -rw-r--r--
copies: avoid instancing more changectx to access parent revisions We just need to know the revision numbers of the parents, creating full context is needlessly expensive. This provide a small, but noticeable performance boost. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 2.885636 comb 2.900000 user 2.870000 sys 0.030000 (median of 10) after: ! wall 2.702270 comb 2.710000 user 2.690000 sys 0.020000 (median of 10) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 4.298271 comb 4.290000 user 4.240000 sys 0.050000 (median of 10) after: ! wall 3.976610 comb 3.970000 user 3.920000 sys 0.050000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.773397 comb 0.770000 user 0.770000 sys 0.000000 (median of 11) after: ! wall 0.701634 comb 0.700000 user 0.700000 sys 0.000000 (median of 13) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013585 comb 0.010000 user 0.010000 sys 0.000000 (median of 217) after: ! wall 0.013550 comb 0.010000 user 0.010000 sys 0.000000 (median of 218) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.003202 comb 0.000000 user 0.000000 sys 0.000000 (median of 929) after: ! wall 0.002993 comb 0.010000 user 0.010000 sys 0.000000 (median of 992) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000077 comb 0.000000 user 0.000000 sys 0.000000 (median of 12060) after: ! wall 0.000072 comb 0.000000 user 0.000000 sys 0.000000 (median of 12804) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.510614 comb 0.500000 user 0.500000 sys 0.000000 (median of 18) after: ! wall 0.473681 comb 0.470000 user 0.470000 sys 0.000000 (median of 20) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.126552 comb 0.130000 user 0.130000 sys 0.000000 (median of 77) after: ! wall 0.115240 comb 0.110000 user 0.110000 sys 0.000000 (median of 85) Differential Revision: https://phab.mercurial-scm.org/D7122
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29871
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     1
from __future__ import absolute_import
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     2
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     3
import cffi
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     4
import os
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     5
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
     6
ffi = cffi.FFI()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
     7
mpatch_c = os.path.join(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
     8
    os.path.join(os.path.dirname(__file__), b'..', b'mpatch.c')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
     9
)
36948
0585337ea787 cleanup: fix some latent open(path).read() et al calls we previously missed
Augie Fackler <augie@google.com>
parents: 32506
diff changeset
    10
with open(mpatch_c) as f:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
    11
    ffi.set_source(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    12
        b"mercurial.cffi._mpatch", f.read(), include_dirs=[b"mercurial"]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
    13
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
    14
ffi.cdef(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
    15
    """
29871
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    16
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    17
struct mpatch_frag {
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    18
       int start, end, len;
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    19
       const char *data;
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    20
};
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    21
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    22
struct mpatch_flist {
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    23
       struct mpatch_frag *base, *head, *tail;
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    24
};
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    25
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    26
extern "Python" struct mpatch_flist* cffi_get_next_item(void*, ssize_t);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    27
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    28
int mpatch_decode(const char *bin, ssize_t len, struct mpatch_flist** res);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    29
ssize_t mpatch_calcsize(size_t len, struct mpatch_flist *l);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    30
void mpatch_lfree(struct mpatch_flist *a);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    31
static int mpatch_apply(char *buf, const char *orig, size_t len,
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    32
                        struct mpatch_flist *l);
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    33
struct mpatch_flist *mpatch_fold(void *bins,
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    34
                       struct mpatch_flist* (*get_next_item)(void*, ssize_t),
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    35
                       ssize_t start, ssize_t end);
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
    36
"""
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36948
diff changeset
    37
)
29871
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    38
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    39
if __name__ == '__main__':
90af59b40d8a mpatch: add setup_mpatch_cffi.py
Maciej Fijalkowski <fijall@gmail.com>
parents:
diff changeset
    40
    ffi.compile()