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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26155209a44b2c77a0d73271bb7f5c4ad9c1788a17db7d28dd328a02e42fda9d
4
- data.tar.gz: 9866bb9a6dbf135bb21b9c69658b557bdec4501a6fef688f1dbc38ac6e50d1f5
3
+ metadata.gz: 19e4e4403a0d37409a7c3c71ab93499a288f7868d68756d7e906dfd8c8033ec3
4
+ data.tar.gz: 8b1984d267cade376fea5c949f98d031d586b11ebf2e17096d749957a1d99af7
5
5
  SHA512:
6
- metadata.gz: 3736dbfa1c4c09e06e9e853f9940809412c1a3e4db72a85fd83ed8ce9cbd967bcd81640ac4cb802d8f49ac786f07bf6ffc02f1973329610dfcdb093758792d5d
7
- data.tar.gz: 854c246d4ae9b47ed3c83a5570b130c4c24f2b4b8b64d9c87528c36b790ce315927a4df5009d5cd81ca89734565dae1511295e0bb95b1be7b0432e363edc2019
6
+ metadata.gz: 7f1329d14f6e96f054db4e36b24addd60db315f63029b3be39d295667079b41fca240fb36fbdf6bc3cc7f5e80851e4db23557370b34728fb1b49e11cfb17d1a3
7
+ data.tar.gz: 41af227e9377d3ac3277f658405561ca7d1ec4ae86c9a1306029fdc34dc7e315a63504f9503305d110d3efaac4503b6e90bcbe0d3f8d864e929322fff38b9a2f
@@ -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
- VALUE cached_entry = rb_hash_lookup(const_refs_hash, filename);
262
-
263
- VALUE current_digest = compute_file_digest(filename);
264
- if (NIL_P(current_digest)) {
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
- VALUE new_entry = rb_hash_new();
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();
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastCov
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_cov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham