fast_cov 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/fast_cov/fast_cov.c +9 -53
- data/lib/fast_cov/compiler.rb +12 -0
- data/lib/fast_cov/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 19e4e4403a0d37409a7c3c71ab93499a288f7868d68756d7e906dfd8c8033ec3
|
|
4
|
+
data.tar.gz: 8b1984d267cade376fea5c949f98d031d586b11ebf2e17096d749957a1d99af7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f1329d14f6e96f054db4e36b24addd60db315f63029b3be39d295667079b41fca240fb36fbdf6bc3cc7f5e80851e4db23557370b34728fb1b49e11cfb17d1a3
|
|
7
|
+
data.tar.gz: 41af227e9377d3ac3277f658405561ca7d1ec4ae86c9a1306029fdc34dc7e315a63504f9503305d110d3efaac4503b6e90bcbe0d3f8d864e929322fff38b9a2f
|
data/ext/fast_cov/fast_cov.c
CHANGED
|
@@ -23,9 +23,6 @@ static ID id_keys;
|
|
|
23
23
|
|
|
24
24
|
// Cache infrastructure
|
|
25
25
|
VALUE fast_cov_cache_hash; // process-level cache (non-static for access from utils)
|
|
26
|
-
static VALUE cDigest; // Digest::MD5
|
|
27
|
-
static ID id_file;
|
|
28
|
-
static ID id_hexdigest;
|
|
29
26
|
static ID id_clear;
|
|
30
27
|
static ID id_merge_bang;
|
|
31
28
|
|
|
@@ -231,52 +228,23 @@ static void on_newobj_event(VALUE tracepoint_data, void *raw_data) {
|
|
|
231
228
|
|
|
232
229
|
// ---- Constant reference resolution (cached) -----------------------------
|
|
233
230
|
|
|
234
|
-
// Computes MD5 hexdigest of a file's contents.
|
|
235
|
-
static VALUE compute_file_digest_body(VALUE filename) {
|
|
236
|
-
VALUE digest_obj = rb_funcall(cDigest, id_file, 1, filename);
|
|
237
|
-
return rb_funcall(digest_obj, id_hexdigest, 0);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
static VALUE compute_file_digest(VALUE filename) {
|
|
241
|
-
int exception_state;
|
|
242
|
-
VALUE result =
|
|
243
|
-
rb_protect(compute_file_digest_body, filename, &exception_state);
|
|
244
|
-
if (exception_state != 0) {
|
|
245
|
-
rb_set_errinfo(Qnil);
|
|
246
|
-
return Qnil;
|
|
247
|
-
}
|
|
248
|
-
return result;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
231
|
// Parse file with Prism and extract constant names.
|
|
252
232
|
static VALUE extract_const_names_body(VALUE filename) {
|
|
253
233
|
return rb_funcall(cConstantExtractor, id_extract, 1, filename);
|
|
254
234
|
}
|
|
255
235
|
|
|
256
236
|
// Returns an array of constant name strings for a file, using the cache.
|
|
237
|
+
// Cache is keyed by filename only - once parsed, results are cached for
|
|
238
|
+
// the lifetime of the process. No digest/mtime validation needed since
|
|
239
|
+
// files don't change during a test suite run.
|
|
257
240
|
static VALUE get_const_refs_for_file(VALUE filename) {
|
|
258
241
|
VALUE const_refs_hash =
|
|
259
242
|
rb_hash_lookup(fast_cov_cache_hash, ID2SYM(rb_intern("const_refs")));
|
|
260
243
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (!NIL_P(cached_entry)) {
|
|
266
|
-
rb_hash_delete(const_refs_hash, filename);
|
|
267
|
-
}
|
|
268
|
-
return Qnil;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Cache hit: digest matches
|
|
272
|
-
if (!NIL_P(cached_entry) && RB_TYPE_P(cached_entry, T_HASH)) {
|
|
273
|
-
VALUE cached_digest =
|
|
274
|
-
rb_hash_lookup(cached_entry, ID2SYM(rb_intern("digest")));
|
|
275
|
-
|
|
276
|
-
if (!NIL_P(cached_digest) &&
|
|
277
|
-
rb_str_equal(cached_digest, current_digest) == Qtrue) {
|
|
278
|
-
return rb_hash_lookup(cached_entry, ID2SYM(rb_intern("refs")));
|
|
279
|
-
}
|
|
244
|
+
// Cache hit: return cached refs
|
|
245
|
+
VALUE cached = rb_hash_lookup(const_refs_hash, filename);
|
|
246
|
+
if (cached != Qnil) {
|
|
247
|
+
return cached;
|
|
280
248
|
}
|
|
281
249
|
|
|
282
250
|
// Cache miss: parse with Prism and extract constant names
|
|
@@ -285,17 +253,11 @@ static VALUE get_const_refs_for_file(VALUE filename) {
|
|
|
285
253
|
rb_protect(extract_const_names_body, filename, &exception_state);
|
|
286
254
|
if (exception_state != 0) {
|
|
287
255
|
rb_set_errinfo(Qnil);
|
|
288
|
-
if (!NIL_P(cached_entry)) {
|
|
289
|
-
rb_hash_delete(const_refs_hash, filename);
|
|
290
|
-
}
|
|
291
256
|
return Qnil;
|
|
292
257
|
}
|
|
293
258
|
|
|
294
|
-
// Store in cache
|
|
295
|
-
|
|
296
|
-
rb_hash_aset(new_entry, ID2SYM(rb_intern("digest")), current_digest);
|
|
297
|
-
rb_hash_aset(new_entry, ID2SYM(rb_intern("refs")), const_names);
|
|
298
|
-
rb_hash_aset(const_refs_hash, filename, new_entry);
|
|
259
|
+
// Store in cache (filename -> refs)
|
|
260
|
+
rb_hash_aset(const_refs_hash, filename, const_names);
|
|
299
261
|
|
|
300
262
|
return const_names;
|
|
301
263
|
}
|
|
@@ -569,16 +531,10 @@ static VALUE fast_cov_stop(VALUE self) {
|
|
|
569
531
|
void Init_fast_cov(void) {
|
|
570
532
|
id_extract = rb_intern("extract");
|
|
571
533
|
id_keys = rb_intern("keys");
|
|
572
|
-
id_file = rb_intern("file");
|
|
573
|
-
id_hexdigest = rb_intern("hexdigest");
|
|
574
534
|
id_clear = rb_intern("clear");
|
|
575
535
|
id_merge_bang = rb_intern("merge!");
|
|
576
536
|
|
|
577
|
-
rb_require("digest/md5");
|
|
578
537
|
rb_require("fast_cov/constant_extractor");
|
|
579
|
-
VALUE mDigest = rb_const_get(rb_cObject, rb_intern("Digest"));
|
|
580
|
-
cDigest = rb_const_get(mDigest, rb_intern("MD5"));
|
|
581
|
-
rb_gc_register_address(&cDigest);
|
|
582
538
|
|
|
583
539
|
// Initialize process-level cache
|
|
584
540
|
fast_cov_cache_hash = rb_hash_new();
|
data/lib/fast_cov/compiler.rb
CHANGED
|
@@ -11,6 +11,8 @@ module FastCov
|
|
|
11
11
|
FAST_COV_DIR = File.expand_path(".", __dir__) # lib/fast_cov/
|
|
12
12
|
|
|
13
13
|
def self.compile!
|
|
14
|
+
clean_ext_dir!
|
|
15
|
+
|
|
14
16
|
Dir.chdir(EXT_DIR) do
|
|
15
17
|
system(RbConfig.ruby, "extconf.rb") || raise("FastCov: extconf.rb failed")
|
|
16
18
|
system("make") || raise("FastCov: make failed")
|
|
@@ -20,6 +22,16 @@ module FastCov
|
|
|
20
22
|
write_digest
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
def self.clean_ext_dir!
|
|
26
|
+
# Clean stale build artifacts to prevent issues when switching Ruby versions
|
|
27
|
+
FileUtils.rm_f(Dir.glob(File.join(EXT_DIR, "*.o")))
|
|
28
|
+
FileUtils.rm_f(Dir.glob(File.join(EXT_DIR, "*.bundle")))
|
|
29
|
+
FileUtils.rm_f(Dir.glob(File.join(EXT_DIR, "*.so")))
|
|
30
|
+
FileUtils.rm_f(File.join(EXT_DIR, "Makefile"))
|
|
31
|
+
FileUtils.rm_f(File.join(EXT_DIR, "mkmf.log"))
|
|
32
|
+
FileUtils.rm_rf(Dir.glob(File.join(EXT_DIR, "*.dSYM")))
|
|
33
|
+
end
|
|
34
|
+
|
|
23
35
|
def self.stale?
|
|
24
36
|
return true unless extension_exists?
|
|
25
37
|
|
data/lib/fast_cov/version.rb
CHANGED