Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
mercurial-devel
Commits
0231f763
Commit
0231f763
authored
17 years ago
by
Bryan O'Sullivan
Browse files
Options
Downloads
Patches
Plain Diff
manifest: improve parsing performance by 8x via a new C extension
parent
1e4ddc9a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mercurial/manifest.py
+2
-9
2 additions, 9 deletions
mercurial/manifest.py
mercurial/parsers.c
+168
-0
168 additions, 0 deletions
mercurial/parsers.c
setup.py
+4
-3
4 additions, 3 deletions
setup.py
with
174 additions
and
12 deletions
mercurial/manifest.py
+
2
−
9
View file @
0231f763
...
...
@@ -8,7 +8,7 @@
from
node
import
bin
,
hex
,
nullid
from
revlog
import
revlog
,
RevlogError
from
i18n
import
_
import
array
,
struct
,
mdiff
import
array
,
struct
,
mdiff
,
parsers
class
manifestdict
(
dict
):
def
__init__
(
self
,
mapping
=
None
,
flags
=
None
):
...
...
@@ -39,14 +39,7 @@
def
parse
(
self
,
lines
):
mfdict
=
manifestdict
()
fdict
=
mfdict
.
_flags
for
l
in
lines
.
splitlines
():
f
,
n
=
l
.
split
(
'
\0
'
)
if
len
(
n
)
>
40
:
fdict
[
f
]
=
n
[
40
:]
mfdict
[
f
]
=
bin
(
n
[:
40
])
else
:
mfdict
[
f
]
=
bin
(
n
)
parsers
.
parse_manifest
(
mfdict
,
mfdict
.
_flags
,
lines
)
return
mfdict
def
readdelta
(
self
,
node
):
...
...
This diff is collapsed.
Click to expand it.
mercurial/parsers.c
0 → 100644
+
168
−
0
View file @
0231f763
/*
parsers.c - efficient content parsing
Copyright 2008 Matt Mackall <mpm@selenic.com> and others
This software may be used and distributed according to the terms of
the GNU General Public License, incorporated herein by reference.
*/
#include
<Python.h>
#include
<ctype.h>
#include
<string.h>
static
int
hexdigit
(
char
c
)
{
if
(
c
>=
'0'
&&
c
<=
'9'
)
return
c
-
'0'
;
if
(
c
>=
'A'
&&
c
<=
'F'
)
return
c
-
'A'
+
10
;
if
(
c
>=
'a'
&&
c
<=
'f'
)
return
c
-
'a'
+
10
;
return
-
1
;
}
/*
* Turn a hex-encoded string into binary.
*/
static
PyObject
*
unhexlify
(
const
char
*
str
,
int
len
)
{
PyObject
*
ret
=
NULL
;
char
*
c
,
*
d
;
if
(
len
%
2
)
{
PyErr_SetString
(
PyExc_ValueError
,
"input is not even in length"
);
goto
bail
;
}
ret
=
PyString_FromStringAndSize
(
NULL
,
len
/
2
);
if
(
!
ret
)
goto
bail
;
d
=
PyString_AsString
(
ret
);
if
(
!
d
)
goto
bail
;
for
(
c
=
str
;
c
<
str
+
len
;)
{
int
hi
=
hexdigit
(
*
c
++
);
int
lo
=
hexdigit
(
*
c
++
);
if
(
hi
==
-
1
||
lo
==
-
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"input contains non-hex character"
);
goto
bail
;
}
*
d
++
=
(
hi
<<
4
)
|
lo
;
}
goto
done
;
bail:
Py_XDECREF
(
ret
);
ret
=
NULL
;
done:
return
ret
;
}
/*
* This code assumes that a manifest is stitched together with newline
* ('\n') characters.
*/
static
PyObject
*
parse_manifest
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
mfdict
,
*
fdict
;
char
*
str
,
*
cur
,
*
start
,
*
zero
;
int
len
;
if
(
!
PyArg_ParseTuple
(
args
,
"O!O!s#:parse_manifest"
,
&
PyDict_Type
,
&
mfdict
,
&
PyDict_Type
,
&
fdict
,
&
str
,
&
len
))
goto
quit
;
for
(
start
=
cur
=
str
,
zero
=
NULL
;
cur
<
str
+
len
;
cur
++
)
{
PyObject
*
file
=
NULL
,
*
node
=
NULL
;
PyObject
*
flags
=
NULL
;
int
nlen
;
if
(
!*
cur
)
{
zero
=
cur
;
continue
;
}
else
if
(
*
cur
!=
'\n'
)
continue
;
if
(
!
zero
)
{
PyErr_SetString
(
PyExc_ValueError
,
"manifest entry has no separator"
);
goto
quit
;
}
file
=
PyString_FromStringAndSize
(
start
,
zero
-
start
);
if
(
!
file
)
goto
bail
;
nlen
=
cur
-
zero
-
1
;
node
=
unhexlify
(
zero
+
1
,
nlen
>
40
?
40
:
nlen
);
if
(
!
node
)
goto
bail
;
if
(
nlen
>
40
)
{
PyObject
*
flags
;
flags
=
PyString_FromStringAndSize
(
zero
+
41
,
nlen
-
40
);
if
(
!
flags
)
goto
bail
;
if
(
PyDict_SetItem
(
fdict
,
file
,
flags
)
==
-
1
)
goto
bail
;
}
if
(
PyDict_SetItem
(
mfdict
,
file
,
node
)
==
-
1
)
goto
bail
;
start
=
cur
+
1
;
zero
=
NULL
;
Py_XDECREF
(
flags
);
Py_XDECREF
(
node
);
Py_XDECREF
(
file
);
continue
;
bail:
Py_XDECREF
(
flags
);
Py_XDECREF
(
node
);
Py_XDECREF
(
file
);
goto
quit
;
}
if
(
len
>
0
&&
*
(
cur
-
1
)
!=
'\n'
)
{
PyErr_SetString
(
PyExc_ValueError
,
"manifest contains trailing garbage"
);
goto
quit
;
}
Py_INCREF
(
Py_None
);
return
Py_None
;
quit:
return
NULL
;
}
static
char
parsers_doc
[]
=
"Efficient content parsing."
;
static
PyMethodDef
methods
[]
=
{
{
"parse_manifest"
,
parse_manifest
,
METH_VARARGS
,
"parse a manifest
\n
"
},
{
NULL
,
NULL
}
};
PyMODINIT_FUNC
initparsers
(
void
)
{
Py_InitModule3
(
"parsers"
,
methods
,
parsers_doc
);
}
This diff is collapsed.
Click to expand it.
setup.py
+
4
−
3
View file @
0231f763
...
...
@@ -88,5 +88,5 @@
cmdclass
=
{
'
install_data
'
:
install_package_data
}
ext_modules
=
[
Extension
(
'
mercurial.
mpatch
'
,
[
'
mercurial/
mpatch
.c
'
]),
Extension
(
'
mercurial.
base85
'
,
[
'
mercurial/
base85
.c
'
]),
Extension
(
'
mercurial.bdiff
'
,
[
'
mercurial/bdiff.c
'
]),
...
...
@@ -92,6 +92,7 @@
Extension
(
'
mercurial.bdiff
'
,
[
'
mercurial/bdiff.c
'
]),
Extension
(
'
mercurial.base85
'
,
[
'
mercurial/base85.c
'
]),
Extension
(
'
mercurial.diffhelpers
'
,
[
'
mercurial/diffhelpers.c
'
])
Extension
(
'
mercurial.diffhelpers
'
,
[
'
mercurial/diffhelpers.c
'
]),
Extension
(
'
mercurial.mpatch
'
,
[
'
mercurial/mpatch.c
'
]),
Extension
(
'
mercurial.parsers
'
,
[
'
mercurial/parsers.c
'
]),
]
packages
=
[
'
mercurial
'
,
'
mercurial.hgweb
'
,
'
hgext
'
,
'
hgext.convert
'
]
...
...
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