@shd101wyy/yo 0.1.5 → 0.1.6

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.
package/std/regex/vm.yo CHANGED
@@ -22,21 +22,18 @@ NfaThread :: object(
22
22
  impl(NfaThread,
23
23
  new : (fn(pc : usize, n_slots : usize) -> Self)({
24
24
  s := ArrayList(usize).with_capacity(n_slots);
25
- i := usize(0);
26
- while (i < n_slots), (i = (i + usize(1))), {
27
- // usize.MAX signals "unset"
28
- s.push(usize.MAX);
29
- };
25
+ // usize.MAX = 0xFF..FF, so memset with 0xFF fills each byte
26
+ s.resize_with_byte(n_slots, int(255));
30
27
  Self(pc: pc, slots: s)
31
28
  }),
32
29
 
33
30
  // Clone a thread with a new PC
34
31
  fork : (fn(self : Self, new_pc : usize) -> Self)({
35
32
  new_slots := ArrayList(usize).with_capacity(self.slots.len());
36
- i := usize(0);
37
- while (i < self.slots.len()), (i = (i + usize(1))), {
38
- new_slots.push(self.slots.get(i).unwrap());
39
- };
33
+ match(self.slots.ptr(),
34
+ .Some(src) => new_slots.extend_from_ptr(src, self.slots.len()),
35
+ .None => ()
36
+ );
40
37
  Self(pc: new_pc, slots: new_slots)
41
38
  })
42
39
  );
@@ -233,14 +230,15 @@ impl(NfaVm,
233
230
  true => ()
234
231
  );
235
232
 
236
- is_seen := seen.*.get(thread.pc).unwrap();
233
+ // Already checked bounds above: thread.pc < instructions.len()
234
+ is_seen := seen.*.get_unchecked(thread.pc);
237
235
  cond(
238
236
  is_seen => { return (); },
239
237
  true => ()
240
238
  );
241
- seen.*.set(thread.pc, true);
239
+ seen.*.set_unchecked(thread.pc, true);
242
240
 
243
- instr := self._program.instructions.get(thread.pc).unwrap();
241
+ instr := self._program.instructions.get_unchecked(thread.pc);
244
242
 
245
243
  match(instr.kind,
246
244
  .Split => {
@@ -326,10 +324,7 @@ impl(NfaVm,
326
324
  sub_next := ArrayList(NfaThread).new();
327
325
 
328
326
  sub_seen := ArrayList(bool).with_capacity(self._program.instructions.len());
329
- si := usize(0);
330
- while (si < self._program.instructions.len()), (si = (si + usize(1))), {
331
- sub_seen.push(false);
332
- };
327
+ sub_seen.resize_with_byte(self._program.instructions.len(), int(0));
333
328
 
334
329
  initial := NfaThread.new(sub_start_pc, self._n_slots);
335
330
  self._add_thread(&(sub_current), initial, start_byte, &(sub_seen));
@@ -376,10 +371,7 @@ impl(NfaVm,
376
371
  sub_blen := decoded.byte_len;
377
372
 
378
373
  // Clear seen
379
- sj := usize(0);
380
- while (sj < sub_seen.len()), (sj = (sj + usize(1))), {
381
- sub_seen.set(sj, false);
382
- };
374
+ sub_seen.fill_with_byte(int(0));
383
375
 
384
376
  // Process consuming instructions
385
377
  st2 := usize(0);
@@ -446,11 +438,9 @@ impl(NfaVm,
446
438
 
447
439
  seen := ArrayList(bool).with_capacity(self._program.instructions.len());
448
440
  next_seen := ArrayList(bool).with_capacity(self._program.instructions.len());
449
- i := usize(0);
450
- while (i < self._program.instructions.len()), (i = (i + usize(1))), {
451
- seen.push(false);
452
- next_seen.push(false);
453
- };
441
+ // Fill with false (0x00) using memset
442
+ seen.resize_with_byte(self._program.instructions.len(), int(0));
443
+ next_seen.resize_with_byte(self._program.instructions.len(), int(0));
454
444
 
455
445
  initial := NfaThread.new(usize(0), self._n_slots);
456
446
  self._add_thread(&(current), initial, start_byte, &(seen));
@@ -474,12 +464,9 @@ impl(NfaVm,
474
464
  true => ()
475
465
  );
476
466
 
477
- // Clear seen flags for this generation
478
- j := usize(0);
479
- while (j < seen.len()), (j = (j + usize(1))), {
480
- seen.set(j, false);
481
- next_seen.set(j, false);
482
- };
467
+ // Clear seen flags for this generation using memset
468
+ seen.fill_with_byte(int(0));
469
+ next_seen.fill_with_byte(int(0));
483
470
 
484
471
  // Process deferred threads targeting this byte_pos
485
472
  new_deferred := ArrayList(DeferredThread).new();