This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
edited.vtt
6624 lines (4416 loc) · 143 KB
/
edited.vtt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
WEBVTT
NOTE duration:"01:36:43"
NOTE language:en-us
00:00:03.000 --> 00:00:08.290
[silence]
00:00:08.290 --> 00:00:10.940
>> Miya: And you should be good.
00:00:10.940 --> 00:00:12.896
>> Stephan: Cool, hi, welcome back to another
00:00:12.896 --> 00:00:14.700
VC Libraries open code review.
00:00:14.700 --> 00:00:16.938
I'm Stephan T. Lavavej, an STL maintainer,
00:00:16.940 --> 00:00:21.979
and today we'll be looking at a PR again,
00:00:21.979 --> 00:00:23.296
PR 2158 extend memcpy,
00:00:23.296 --> 00:00:25.052
memmove and memcmp optimizations
00:00:25.052 --> 00:00:27.619
from our contributor Adam Bucior.
00:00:27.620 --> 00:00:30.240
So let me go ahead and share out my screen.
00:00:33.920 --> 00:00:35.268
And here we go.
00:00:37.420 --> 00:00:38.050
'kay.
00:00:42.230 --> 00:00:45.716
So resuming the review that I left
00:00:45.716 --> 00:00:49.370
off last week, I got through up to
00:00:49.370 --> 00:00:52.286
line, right line 4005 of <xutility>.
00:00:52.286 --> 00:00:54.710
One of our central internal headers,
00:00:54.710 --> 00:00:56.369
not the most central, but fairly central.
00:00:56.370 --> 00:00:59.130
Contains lots of commonly used algorithms,
00:00:59.130 --> 00:01:00.920
so we'll be resuming there.
00:01:00.920 --> 00:01:06.218
Adam also pushed one commit to update a
00:01:06.218 --> 00:01:09.688
comment. So, let's just check that.
00:01:09.690 --> 00:01:11.450
It adds a comma, addressing the one comment
00:01:11.450 --> 00:01:13.269
I had from the last time, excellent.
00:01:13.270 --> 00:01:15.454
OK, so that's good.
00:01:15.454 --> 00:01:18.270
Uh, let's get this to disappear.
00:01:18.270 --> 00:01:21.414
OK, so, let's go look at the code.
00:01:25.770 --> 00:01:27.570
We got all the product code
00:01:27.570 --> 00:01:29.432
reviewed except for <xutility> and
00:01:29.432 --> 00:01:31.525
then we've got tests to look at.
00:01:31.530 --> 00:01:35.680
OK, so let's load this diff.
00:01:35.680 --> 00:01:39.180
Scroll down to, right line 4005.
00:01:43.040 --> 00:01:45.483
I seem to recall, at least for
00:01:45.483 --> 00:01:47.975
this top part I had chosen to split
00:01:47.975 --> 00:01:50.250
left and right, rather than inline.
00:01:50.250 --> 00:01:53.730
Let me see if… here's 4005, let
00:01:53.730 --> 00:01:56.320
me see if the stuff below it
00:01:56.320 --> 00:01:57.930
would benefit from being split.
00:02:00.180 --> 00:02:02.310
This part kind of yes,
00:02:02.310 --> 00:02:06.190
not massively… well yeah here,
00:02:06.190 --> 00:02:08.458
here this is kind of a…
00:02:08.460 --> 00:02:10.756
I guess it's a rename plus a refactoring.
00:02:13.620 --> 00:02:15.492
The diff isn't quite to the
00:02:15.492 --> 00:02:16.740
point where it's unreadable.
00:02:16.740 --> 00:02:19.410
This is like, here this is,
00:02:19.410 --> 00:02:22.632
uh, sort of almost looks like
00:02:22.632 --> 00:02:24.623
unrelated code getting… uh, it's
00:02:24.623 --> 00:02:27.234
jumping in and out of add/remove
00:02:27.234 --> 00:02:29.849
because it sees these empty lines.
00:02:29.850 --> 00:02:31.943
And the diff algorithm used can be
00:02:31.943 --> 00:02:33.819
responsible for this sort of behavior.
00:02:33.820 --> 00:02:35.675
This down here is enough that I
00:02:35.675 --> 00:02:37.706
think I wanna use side by side, OK.
00:02:39.790 --> 00:02:42.240
So let's do that, click the gear, split,
00:02:42.240 --> 00:02:45.210
may as well hide whitespace changes.
00:02:48.950 --> 00:02:51.470
I could also use the VS Code
00:02:51.470 --> 00:02:52.847
GitHub extension, but I'm more
00:02:52.847 --> 00:02:54.780
used to the web UI at this point.
00:02:57.220 --> 00:02:59.271
The VS Code extension is very nice because
00:02:59.271 --> 00:03:01.785
it lets you see an arbitrary amount of
00:03:01.785 --> 00:03:04.010
context around the lines being edited,
00:03:04.010 --> 00:03:06.236
you don't have to click more.
00:03:06.240 --> 00:03:08.515
I should get used to using it.
00:03:08.520 --> 00:03:10.487
OK, so here's where we reviewed <xutility>
00:03:10.487 --> 00:03:12.956
up to but not including this line.
00:03:12.960 --> 00:03:15.612
I always pay attention to my
00:03:15.612 --> 00:03:16.938
inclusive/exclusive issues.
00:03:16.940 --> 00:03:19.495
So go ahead and resolve this, and
00:03:19.495 --> 00:03:22.099
let's pick up where we left off.
00:03:22.100 --> 00:03:26.108
OK, so this is the _Copy_unchecked algorithm.
00:03:26.110 --> 00:03:27.888
Here we are copying a range [_First, _Last)
00:03:27.890 --> 00:03:30.530
to a destination iterator.
00:03:30.530 --> 00:03:32.610
It's internal and it's unchecked,
00:03:32.610 --> 00:03:34.731
saying that we are going to assume
00:03:34.731 --> 00:03:36.476
that the iterator range is valid
00:03:36.476 --> 00:03:38.526
and that we have sufficient space
00:03:38.526 --> 00:03:42.082
in _Dest. We have outer layers, um,
00:03:42.090 --> 00:03:44.550
like the publicly accessible std::copy
00:03:44.550 --> 00:03:46.747
function that will perform iterator
00:03:46.747 --> 00:03:49.142
debugging checks when possible to do
00:03:49.142 --> 00:03:50.724
things like make sure that the first
00:03:50.724 --> 00:03:52.579
and last iterators are not reversed.
00:03:52.580 --> 00:03:54.146
If you accidentally say, like,
00:03:54.150 --> 00:03:56.369
(v.end(), v.begin()), or if you mismatch
00:03:56.370 --> 00:03:58.190
them into different containers, like,
00:03:58.190 --> 00:04:01.368
uh, (v.begin(), v2.end()), that would be bad.
00:04:01.368 --> 00:04:02.856
Or if the destination range does
00:04:02.856 --> 00:04:03.940
not have enough space,
00:04:03.940 --> 00:04:07.009
uh, we can detect that sometimes if we can,
00:04:07.010 --> 00:04:07.516
umm, sense
00:04:07.516 --> 00:04:09.540
how many elements are in the input
00:04:09.593 --> 00:04:11.231
range by doing like a difference
00:04:11.231 --> 00:04:12.900
on forward or better iterators.
00:04:12.900 --> 00:04:16.113
And if the output range is forward or better,
00:04:16.120 --> 00:04:17.534
and especially if it's a random access,
00:04:17.540 --> 00:04:20.137
we can see whether we can form,
00:04:20.140 --> 00:04:22.928
you know _Dest + N or next(_Dest, N)
00:04:22.928 --> 00:04:25.476
and see if that's valid.
00:04:25.480 --> 00:04:27.178
And then once we have verified
00:04:27.180 --> 00:04:29.910
that the iterators are not reversed,
00:04:29.910 --> 00:04:31.002
and that there's sufficient
00:04:31.002 --> 00:04:32.094
space in the destination.
00:04:32.452 --> 00:04:35.268
We can do what we call unwrap the
00:04:35.268 --> 00:04:38.026
iterators down to either raw pointers
00:04:38.026 --> 00:04:40.897
for contiguous things or unchecked class
00:04:40.897 --> 00:04:43.711
types that don't do iterator debugging
00:04:43.711 --> 00:04:45.800
logic to sort of avoid overhead,
00:04:45.800 --> 00:04:47.528
especially in debug mode.
00:04:47.528 --> 00:04:49.600
Uh, where we don't get inlining
00:04:49.600 --> 00:04:50.912
or any fancy optimizations.
00:04:51.248 --> 00:04:54.200
So that's what _Copy_unchecked is doing here.
00:04:54.560 --> 00:04:57.080
We have a note as a reminder
00:04:57.080 --> 00:04:59.560
that things other than just std::copy
00:04:59.560 --> 00:05:01.680
will directly call this.
00:05:01.680 --> 00:05:03.200
We don't usually note this,
00:05:03.200 --> 00:05:05.504
but the pattern of having unchecked
00:05:05.504 --> 00:05:07.548
helpers just exist to implement
00:05:07.548 --> 00:05:09.738
the public functions is strong
00:05:09.738 --> 00:05:12.071
enough that when there's direct
00:05:12.071 --> 00:05:14.119
callers to something unchecked,
00:05:14.120 --> 00:05:16.374
we did start adding some of these
00:05:16.374 --> 00:05:19.268
comments here, just as a reminder.
00:05:19.270 --> 00:05:19.735
OK,
00:05:19.735 --> 00:05:22.525
so this is changing from
00:05:22.525 --> 00:05:24.730
_Ptr_copy_cat to _Iter_copy_cat.
00:05:24.730 --> 00:05:27.045
That's the rename because it's being
00:05:27.045 --> 00:05:28.897
generalized, and _Trivially_copyable
00:05:28.897 --> 00:05:30.739
changes to _Trivially_assignable
00:05:30.739 --> 00:05:33.361
because here we are assigning over
00:05:33.361 --> 00:05:35.170
elements that already exist,
00:05:35.170 --> 00:05:39.470
this is not the uninitialized special
00:05:39.470 --> 00:05:42.350
algorithm that will fill raw memory.
00:05:42.350 --> 00:05:43.590
So this is correct.
00:05:43.590 --> 00:05:45.932
This is that make the type traits
00:05:45.932 --> 00:05:48.007
we're using more fine grained.
00:05:48.010 --> 00:05:49.099
OK, so down here,
00:05:49.099 --> 00:05:51.277
this looks like a ranges version
00:05:51.280 --> 00:05:53.396
let me expand some context.
00:05:53.396 --> 00:05:57.600
We've got the ranges helper _Copy_unchecked,
00:05:57.600 --> 00:05:59.460
I can tell it's ranges because
00:05:59.460 --> 00:06:01.740
it's got all this sentinel stuff.
00:06:01.740 --> 00:06:03.048
Here, _Ptr_copy_cat,
00:06:03.048 --> 00:06:04.029
renamed _Iter_copy_cat,
00:06:04.030 --> 00:06:05.794
_Trivially_copyable changed to
00:06:05.794 --> 00:06:06.970
_Trivially_assignable,
00:06:06.970 --> 00:06:09.080
same rationale, writing to an
00:06:09.080 --> 00:06:11.016
_Out that already exists and
00:06:11.016 --> 00:06:12.246
not changing the sized_sentinel_for
00:06:12.250 --> 00:06:15.806
thing: this is the ranges idea –
00:06:15.810 --> 00:06:17.706
Trying to avoid using the word
00:06:17.706 --> 00:06:18.970
concept to avoid confusion.
00:06:18.970 --> 00:06:23.366
– the ranges idea that you can
00:06:23.366 --> 00:06:26.504
have a range and in C++20 ranges
00:06:26.504 --> 00:06:28.053
the sentinel that denotes the
00:06:28.053 --> 00:06:29.901
end of the range does not have
00:06:29.901 --> 00:06:31.886
to be the same type as the
00:06:31.890 --> 00:06:34.915
iterator, so it's generalizing the
00:06:34.915 --> 00:06:38.677
classic iterator pattern from C++98's STL,
00:06:38.680 --> 00:06:40.468
and this allows you to have
00:06:40.468 --> 00:06:42.803
ranges like, oh, I have a pointer
00:06:42.803 --> 00:06:44.583
to a null terminated string,
00:06:44.590 --> 00:06:46.480
and I know when I'm going to hit the end,
00:06:46.480 --> 00:06:49.468
if you traverse it from front to back.
00:06:49.468 --> 00:06:50.860
But I don't know exactly where
00:06:50.914 --> 00:06:52.306
that's going to be until we
00:06:52.306 --> 00:06:53.660
actually look at every element,
00:06:53.660 --> 00:06:56.072
so the sentinel can be a
00:06:56.072 --> 00:06:57.726
special type that says, hey,
00:06:57.726 --> 00:06:59.700
I've reached the end of the range
00:06:59.700 --> 00:07:01.236
if the iterator on the left
00:07:01.236 --> 00:07:02.960
hand side of the comparison
00:07:02.960 --> 00:07:05.666
is pointing to a null character.
00:07:06.005 --> 00:07:08.685
So that's an example of a sentinel that
00:07:08.685 --> 00:07:11.150
does not have the same type as the iterator.
00:07:11.150 --> 00:07:14.696
Some sentinels can actually tell you
00:07:14.696 --> 00:07:19.390
the size of a range, that happens for
00:07:19.390 --> 00:07:21.202
things like forward or better iterators,
00:07:21.202 --> 00:07:23.156
where they are the same type, where the
00:07:23.156 --> 00:07:24.764
sentinel is the same type as the iterator.
00:07:24.770 --> 00:07:26.630
You just do a classic difference.
00:07:26.630 --> 00:07:30.158
It can also happen in some cases for
00:07:30.158 --> 00:07:32.966
something I believe like a list,
00:07:32.970 --> 00:07:35.658
where the list knows its own size,
00:07:35.660 --> 00:07:38.906
but, uh, arbitrary iterators may not.
00:07:38.910 --> 00:07:40.656
Uh, I may be incorrect
00:07:40.660 --> 00:07:41.564
there is that wrong?
00:07:41.564 --> 00:07:42.946
>> Casey: That's not exactly this one, right?
00:07:42.946 --> 00:07:44.668
So sized_sentinel_for means that the
00:07:44.668 --> 00:07:46.099
iterator and sentinel can tell
00:07:46.099 --> 00:07:47.574
you the distance between them.
00:07:47.580 --> 00:07:49.288
list is an example of a range
00:07:49.288 --> 00:07:50.410
that's a sized range.
00:07:50.410 --> 00:07:51.880
It knows its own size,
00:07:51.880 --> 00:07:54.225
but the iterators and sentinels don't know
00:07:54.225 --> 00:07:56.048
the distance between them.
>> Stephan: Thank you.
00:07:56.048 --> 00:07:58.000
OK, I thought I was getting that wrong, and, uh…
00:07:58.000 --> 00:07:59.257
>> Casey: you were close.
00:07:59.257 --> 00:08:02.190
That's definitely, you know, list is the important example,
00:08:02.190 --> 00:08:03.625
but it's the important example of the
00:08:03.630 --> 00:08:04.770
other property than the one you
00:08:04.770 --> 00:08:05.340
were looking at.
00:08:05.340 --> 00:08:07.620
>> Stephan: Yeah, the sized_range, OK.
00:08:07.620 --> 00:08:08.184
Awesome, so yeah,
00:08:08.184 --> 00:08:08.936
and sized_sentinel_for
00:08:08.940 --> 00:08:10.244
is definitely the one we want
00:08:10.244 --> 00:08:11.457
here because at this point we're just
00:08:11.457 --> 00:08:12.700
being given an iterator and a sentinel,
00:08:12.700 --> 00:08:15.600
not an entire range.
00:08:15.600 --> 00:08:17.220
OK, so this is good,
00:08:17.220 --> 00:08:19.680
uh, let's scroll down some more.
00:08:19.680 --> 00:08:20.358
Um, OK,
00:08:20.358 --> 00:08:22.731
now we've got copy_n, the version
00:08:22.731 --> 00:08:25.176
that takes N number of elements.
00:08:25.180 --> 00:08:27.490
This is the
00:08:27.490 --> 00:08:30.084
classic std version, uh,
00:08:30.084 --> 00:08:31.788
there is no unchecked form because
00:08:31.788 --> 00:08:33.698
we're doing the unchecking in here.
00:08:33.700 --> 00:08:36.260
Umm, so _Ptr_copy_cat renamed _Iter_copy_cat,
00:08:36.260 --> 00:08:38.440
_Trivially_copyable to _Trivially_assignable.
00:08:38.440 --> 00:08:40.258
Yep, it's not the uninitialized form,
00:08:40.260 --> 00:08:42.000
so all good.
00:08:42.000 --> 00:08:46.065
We've got a _Copy_backward_unchecked.
00:08:46.065 --> 00:08:49.165
Yeah, that looks good.
00:08:49.702 --> 00:08:52.362
this is the internal version
00:08:52.362 --> 00:08:53.958
taking bidirectional iterators.
00:08:53.960 --> 00:08:56.070
_Ptr_copy_cat renamed _Iter_copy_cat,
00:08:56.070 --> 00:08:58.180
_Trivially_copyable to _Trivially_assignable.
00:08:58.180 --> 00:08:59.293
Yep, that's good.
00:08:59.293 --> 00:09:01.519
Nothing about this would be different.
00:09:01.520 --> 00:09:02.705
OK, _Move_unchecked,
00:09:02.705 --> 00:09:05.470
_Ptr_move_cat, because we're gonna
00:09:05.547 --> 00:09:08.018
move elements, is now _Iter_move_cat,
00:09:08.020 --> 00:09:09.624
that's good, _Trivially_copyable
00:09:09.624 --> 00:09:10.827
to _Trivially_assignable.
00:09:10.830 --> 00:09:13.310
Yep, the elements already exist.
00:09:13.310 --> 00:09:14.785
_Move_backward_unchecked, um, this
00:09:14.785 --> 00:09:16.630
one goes in the opposite order,
00:09:16.630 --> 00:09:19.766
which helps in certain overlapping cases.
00:09:19.770 --> 00:09:22.422
Uh, _Ptr_move_cat to _Iter_move_cat,
00:09:22.422 --> 00:09:24.046
that's correct, _Trivially_copyable
00:09:24.050 --> 00:09:24.986
to _Trivially_assignable,
00:09:24.986 --> 00:09:26.234
again, the elements exist,
00:09:26.240 --> 00:09:28.418
so that's good.
00:09:28.420 --> 00:09:31.486
OK, so now for something slightly different.
00:09:34.130 --> 00:09:37.253
This is one of the things that Adam had called
00:09:37.253 --> 00:09:40.795
out in his extensive PR notes that I really
00:09:40.795 --> 00:09:43.388
appreciate. The changes to _Is_all_bits_zero,
00:09:43.390 --> 00:09:47.128
so this is used by the fill
00:09:47.128 --> 00:09:50.060
optimization that will call memset.
00:09:50.060 --> 00:09:52.780
If we're gonna fill it with an element,
00:09:52.780 --> 00:09:55.417
and if that element happens to be 0, uh,
00:09:55.420 --> 00:09:57.160
we can just call mems… memset,
00:09:57.160 --> 00:09:58.582
and it doesn't matter how many bytes it is,
00:09:58.590 --> 00:10:00.422
as long as all of the bits of
00:10:00.422 --> 00:10:01.698
that element type are zero.
00:10:01.700 --> 00:10:05.813
I believe this is this was from a previous
00:10:05.813 --> 00:10:07.960
generalization of our optimization.
00:10:07.960 --> 00:10:09.928
This is being further extended to
00:10:09.928 --> 00:10:11.578
handle nullptr_t, because
00:10:11.578 --> 00:10:13.606
if we're being given an element,
00:10:13.610 --> 00:10:15.834
say, say we're being asked to fill a
00:10:15.834 --> 00:10:17.998
range of pointers, like char*s,
00:10:18.000 --> 00:10:19.824
const char*s, whatever.
00:10:19.824 --> 00:10:23.260
And the element that we're given to fill
00:10:23.260 --> 00:10:25.585
happens to be nullptr, the literal constant.
00:10:25.585 --> 00:10:27.179
That's saying, hey,
00:10:27.179 --> 00:10:28.970
I want you to null out all these pointers.
00:10:28.970 --> 00:10:32.400
So this will detect that hey,
00:10:32.400 --> 00:10:34.920
if the element we're being given is nullptr_t,
00:10:34.920 --> 00:10:36.180
we can just always return true.
00:10:39.230 --> 00:10:41.801
And we can do so at compile time.
00:10:41.801 --> 00:10:44.449
What this code would have done is it
00:10:44.449 --> 00:10:47.018
would have made a constexpr for,
00:10:47.020 --> 00:10:48.500
whoa, I'm zooming in a bit,
00:10:48.500 --> 00:10:50.066
It would have made a constexpr
00:10:50.066 --> 00:10:51.500
object of type nullptr,
00:10:51.500 --> 00:10:54.850
and then memcmp'd it at runtime.
00:10:54.850 --> 00:10:56.218
So we would get the answer
00:10:56.220 --> 00:10:57.879
yes, it's all bits zero, but we would
00:10:57.879 --> 00:10:59.340
have had to call memcmp to do so.
00:10:59.340 --> 00:11:00.888
For nullptr we can just
00:11:00.888 --> 00:11:03.347
statically detect it. So why not?
00:11:03.347 --> 00:11:07.260
This improves codegen a little bit more.
00:11:07.260 --> 00:11:08.828
And this does seem like a common enough
00:11:08.828 --> 00:11:10.608
case to be worth optimizing, like fill
00:11:10.608 --> 00:11:12.386
a range of pointers with nullptr,
00:11:12.390 --> 00:11:14.917
maybe, they were uninitialized before,
00:11:14.920 --> 00:11:16.446
maybe we need to reset them all.
00:11:16.450 --> 00:11:18.890
Seems totally reasonable and
00:11:18.890 --> 00:11:19.940
we can do this thanks to nullptr_t
00:11:19.940 --> 00:11:21.340
being in the type system.
00:11:21.340 --> 00:11:22.410
When things're in the type system,
00:11:22.410 --> 00:11:25.506
that's good, when things like 0 is a
00:11:25.506 --> 00:11:28.046
null pointer constant are rules that exist
00:11:28.046 --> 00:11:32.488
outside the type system, that leads to misery,
00:11:32.490 --> 00:11:34.320
as we saw from years and years
00:11:34.320 --> 00:11:35.929
of experience with C++98.
00:11:35.930 --> 00:11:38.639
So, if constexpr (is_same_v<_Ty, nullptr_t>)
00:11:38.639 --> 00:11:41.549
then just always return true.
00:11:41.550 --> 00:11:43.762
Otherwise do existing code.
00:11:43.762 --> 00:11:47.850
This is correct because we are already
00:11:47.850 --> 00:11:49.684
taking this thing by const _Ty&,
00:11:49.690 --> 00:11:51.286
so we don't need to worry
00:11:51.286 --> 00:11:52.084
about CV qualifiers.
00:11:52.090 --> 00:11:54.106
is_same_v is very very strict.
00:11:54.110 --> 00:11:56.774
It wants the type to be exactly identical
00:11:56.774 --> 00:11:59.796
and any differences in constness or
00:11:59.796 --> 00:12:02.698
volatility will cause this to report false.
00:12:02.700 --> 00:12:04.200
Here this will ignore constness,
00:12:04.200 --> 00:12:05.370
it ignores value category because
00:12:05.370 --> 00:12:06.980
we're already taking it by reference,
00:12:06.980 --> 00:12:07.704
so this is good.
00:12:07.704 --> 00:12:08.790
And if somebody gives us a
00:12:08.835 --> 00:12:09.720
volatile nullptr,
00:12:09.720 --> 00:12:11.376
well they deserve what they get.
00:12:11.380 --> 00:12:13.641
We'll go through this code path
00:12:13.641 --> 00:12:16.480
and I think memcmp handles volatile?
00:12:16.480 --> 00:12:17.564
I think it does.
00:12:17.564 --> 00:12:18.377
Maybe it doesn't,
00:12:18.380 --> 00:12:20.140
but in any event it's not going to
00:12:20.140 --> 00:12:22.241
be a regression, so that's good.
00:12:22.241 --> 00:12:24.530
And, I'm trying to think, are there any
00:12:24.601 --> 00:12:27.137
other types that we could do this for?
00:12:27.140 --> 00:12:27.764
Brain says no,
00:12:27.764 --> 00:12:29.220
there's no other types that are like
00:12:29.268 --> 00:12:30.700
nullptr_t, that we can just say hey,
00:12:30.700 --> 00:12:33.028
you're always 0, every other type
00:12:33.030 --> 00:12:34.290
Can store something useful.
00:12:36.580 --> 00:12:40.740
Umm, OK, next, and I was just thinking,
00:12:40.740 --> 00:12:42.498
um, that you could have something
00:12:42.498 --> 00:12:44.239
like a struct who's only data member is
00:12:44.239 --> 00:12:46.038
a nullptr, but we can't sense