xre 0.5.2-x86_64-darwin → 0.5.4-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -20
- data/lib/xre/version.rb +1 -1
- data/lib/xre/xre.bundle +0 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2820731414ce8e3b3700dfbcb2adf943a9d6e12246dee1e205fb09c45a8b0ca6
|
4
|
+
data.tar.gz: 30de4b46256476eee21cf39b5e2ec036354dd52ee9a061b477c21a3d871b6844
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c135babf92993097270aa1cfe8877878f5b14745bd4628f4d89550b30f46239eee2b368f65faeb00667b5b6100e4ef0f6c8b45f811d3c63f718ea458bf174ea3
|
7
|
+
data.tar.gz: 3db4bc888d0e2296cdb09a547c4037754bbe4eccd8476433dbd3dc2919f89def86c0282953d11f4b5eed77a8f40faad1faa006fd607d6033ad4f2c88c8f0eafe
|
data/README.md
CHANGED
@@ -3,18 +3,57 @@
|
|
3
3
|
This is a rust extension for finding all the matches in a text.
|
4
4
|
It's a simple extension that is used in one part of our codebase and this extension makes it substantially faster.
|
5
5
|
|
6
|
-
|
6
|
+
## Why?
|
7
7
|
|
8
|
-
|
8
|
+
The main reason for this extension is that we have a unique use case where we need to find all captures
|
9
|
+
with their respectful offsets in a large text and we need to do this for a huge number of regexes and texts.
|
10
|
+
This is a slow operation in ruby since the regular `scan` does not provide the actual captures,
|
11
|
+
but only the offsets. This extension provides the captures and offsets in a single call for a
|
12
|
+
list of regexes to avoid the overhead of calling the regex engine multiple times.
|
13
|
+
|
14
|
+
Moreover, another part of the problem is that we also require the surrounding text of the capture
|
15
|
+
with some radius, which is also not possible with the regular `scan` method without resorting to iterating
|
16
|
+
the whole text multiple times.
|
17
|
+
|
18
|
+
> 🤓
|
19
|
+
> Another a bit more technical reason for why the rust extension is faster is that ruby strings are
|
20
|
+
> indexed in characters(`O(n)`), but rust strings are indexed in bytes(`O(1)`). And with a careful
|
21
|
+
> iteration over the characters on the rust side(see `regex_list.rs#captures_with_context` and `utils.rs#find_char_index`) as we go through the text we can avoid multiple(`n`)
|
22
|
+
> `O(n)` operations that ruby would have to do, reducing the algorithmic complexity from
|
23
|
+
> `O(n^2)` to `O(n)` for one regex, and from `O(m * n^2)` to `O(m * n)`(where `m` and `n` are the number
|
24
|
+
> of regexes and the number of texts respectfuly) for multiple regexes.
|
25
|
+
|
26
|
+
## Developing:
|
27
|
+
|
28
|
+
The simplest way to develop the gem locally without reinstalling the gem is to just:
|
29
|
+
|
30
|
+
1. change the
|
31
|
+
`gem "xre"` in the `Gemfile` to `gem "xre", path: "xre"`
|
32
|
+
2. run `bundle install`
|
33
|
+
|
34
|
+
and you're good to go. Just change the code(then compile the rust code if you changed it, more on that below),
|
35
|
+
go into `rails c` and hack away.
|
36
|
+
|
37
|
+
Another simple way is to:
|
38
|
+
|
39
|
+
1. change the gem code(then, once again, compile the rust code if you changed it)
|
40
|
+
2. go into `rails c` or the console of your choosing
|
41
|
+
3. run `require_relative "xre/lib/xre"`
|
42
|
+
|
43
|
+
all done.
|
44
|
+
|
45
|
+
> 💡Note: _The following part of the readme assumes that you're in the `xre` directory inside `clearscope` project._
|
46
|
+
|
47
|
+
### How to build rust code locally:
|
9
48
|
|
10
49
|
```bash
|
11
|
-
rake compile
|
50
|
+
rake compile # or just rake
|
12
51
|
```
|
13
52
|
|
14
53
|
sometimes you might need to clean the build:
|
15
54
|
|
16
55
|
```bash
|
17
|
-
rake clean
|
56
|
+
rake clean && rake compile
|
18
57
|
```
|
19
58
|
|
20
59
|
you might need to install rust toolchain for that:
|
@@ -23,32 +62,34 @@ you might need to install rust toolchain for that:
|
|
23
62
|
curl https://sh.rustup.rs -sSf | sh
|
24
63
|
```
|
25
64
|
|
26
|
-
|
27
|
-
|
28
|
-
### Ruby tests:
|
65
|
+
### How to run tests:
|
29
66
|
|
30
|
-
|
67
|
+
**Ruby tests:**
|
31
68
|
|
32
69
|
```bash
|
33
|
-
bundle exec
|
70
|
+
bundle exec rake spec
|
34
71
|
```
|
35
72
|
|
36
|
-
|
73
|
+
**Rust tests:**
|
37
74
|
|
38
75
|
```bash
|
39
|
-
cargo test
|
76
|
+
cargo test # you will need rust toolchain for that
|
40
77
|
```
|
41
78
|
|
42
|
-
|
79
|
+
**Rust linting:**
|
43
80
|
|
44
|
-
|
81
|
+
````bash
|
82
|
+
# you will need rust toolchain for that
|
83
|
+
cargo fmt # will format the code
|
84
|
+
cargo clippy # will suggest improvements, not only style ones
|
85
|
+
```
|
45
86
|
|
46
|
-
|
87
|
+
## Publishing:
|
47
88
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
89
|
+
The codebase includes `xre/Rakefile` which in turn defines a `gem:native`
|
90
|
+
task that compiles the extension for the `x86_64-linux`, `x86_64-darwin`, and `arm64-darwin`
|
91
|
+
and puts the compiled gems into `xre/pkg/` directory, from where one should
|
92
|
+
`gem push xre-<version>-x86_64-linux.gem` to publish the gem.
|
52
93
|
|
53
|
-
> Note
|
54
|
-
|
94
|
+
> Note: You will need a docker installed on your machine for that
|
95
|
+
````
|
data/lib/xre/version.rb
CHANGED
data/lib/xre/xre.bundle
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- barseek
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -27,7 +27,6 @@ licenses:
|
|
27
27
|
metadata:
|
28
28
|
homepage_uri: https://github.com/vagab/xre
|
29
29
|
source_code_uri: https://github.com/vagab/xre
|
30
|
-
rubygems_mfa_required: 'true'
|
31
30
|
post_install_message:
|
32
31
|
rdoc_options: []
|
33
32
|
require_paths:
|