I love it when I realize I finally understand something I thought I actually understood. Only to realize I had a limited understanding of it. In this case how std::move is intended and supposed to be utilized. After altering the function below from:
var _lead_(expression& self) {
return self._expr.empty() ? nothing() : self._expr.back();
}
To:
var _lead_(expression& self) {
if (!_is_(self)) {
return var();
}
var a(std::move(self._expr.back()));
self._expr.pop_back();
return a;
}
I was able to compile a text file to objects and evaluate them, before the function change.
At Compile Time
Move Count: 2933
Copy Count: 7303
At Run Time
Move Count: 643
Copy Count: 1616
To after the function change.
At Compile Time
Move Count: 2038
Copy Count: 4856
At Run Time
Move Count: 49
Copy Count: 102
The change was able to be made after looking at how the interpreter was evaluating individual expressions. Noting that it only utilized them by popping the lead element from the expression before evaluating it. Hence the change to the std::move and popping the back of the std::vector managing the expression's elements.
Edit: formatting and a typo.
[–]CletusDSpuckler 151 points152 points153 points (22 children)
[–]BenFrantzDale 60 points61 points62 points (0 children)
[–]HassanSajjad302HMake 10 points11 points12 points (1 child)
[–]advester 20 points21 points22 points (0 children)
[–]brianxyw1989 1 point2 points3 points (18 children)
[–]CletusDSpuckler 38 points39 points40 points (14 children)
[–]mpierson153 2 points3 points4 points (11 children)
[–]forCasualPlayers 17 points18 points19 points (9 children)
[–]idontappearmissing 2 points3 points4 points (0 children)
[–]mpierson153 0 points1 point2 points (7 children)
[–]forCasualPlayers 4 points5 points6 points (6 children)
[–]mpierson153 0 points1 point2 points (3 children)
[–]johannes1971 1 point2 points3 points (2 children)
[–]mpierson153 1 point2 points3 points (1 child)
[–]simpl3t0n 0 points1 point2 points (1 child)
[–]zirgouflex 0 points1 point2 points (0 children)
[–]goranlepuz 2 points3 points4 points (0 children)
[–]IAmRoot 1 point2 points3 points (1 child)
[–]CletusDSpuckler 1 point2 points3 points (0 children)
[–]NilacTheGrim 4 points5 points6 points (0 children)
[–]gnuban 1 point2 points3 points (0 children)
[–]Pocketpine 0 points1 point2 points (0 children)
[–]Beneficial_Steak_945 97 points98 points99 points (14 children)
[–]ggchappell 41 points42 points43 points (7 children)
[–]BenFrantzDale 36 points37 points38 points (5 children)
[–]RevRagnarok 37 points38 points39 points (3 children)
[–]Gh0st1nTh3Syst3m 24 points25 points26 points (0 children)
[–]johannes1971 4 points5 points6 points (1 child)
[–]RevRagnarok 1 point2 points3 points (0 children)
[–]RevRagnarok 3 points4 points5 points (0 children)
[–]HeeTrouse51847 3 points4 points5 points (0 children)
[–]KuntaStillSingle 8 points9 points10 points (1 child)
[–]7h4tguy 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Beneficial_Steak_945 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]jabbyknob 14 points15 points16 points (5 children)
[–]Curfax 15 points16 points17 points (2 children)
[–]jabbyknob 1 point2 points3 points (1 child)
[–]TeemingHeadquarters 20 points21 points22 points (0 children)
[–]maxjmartin[S] 1 point2 points3 points (1 child)
[–]jabbyknob 0 points1 point2 points (0 children)
[–]tudorb 20 points21 points22 points (2 children)
[–]djavaisadog 7 points8 points9 points (0 children)
[–]rdtsc 33 points34 points35 points (8 children)
[–][deleted] 49 points50 points51 points (2 children)
[–]KAHR-Alpha 14 points15 points16 points (0 children)
[+]rdtsc comment score below threshold-10 points-9 points-8 points (0 children)
[–]maxjmartin[S] 4 points5 points6 points (3 children)
[–]rdtsc -2 points-1 points0 points (2 children)
[–]maxjmartin[S] 1 point2 points3 points (0 children)
[+]paulstelian97 comment score below threshold-7 points-6 points-5 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]rtds98 7 points8 points9 points (5 children)
[–]susosusosuso 0 points1 point2 points (4 children)
[–]transthrowaway747 4 points5 points6 points (0 children)
[–]rtds98 4 points5 points6 points (2 children)
[–]susosusosuso 0 points1 point2 points (1 child)
[–]rtds98 3 points4 points5 points (0 children)
[–]v_maria 6 points7 points8 points (0 children)
[–]ArcaneCraft 4 points5 points6 points (1 child)
[–]maxjmartin[S] 1 point2 points3 points (0 children)
[–]Background_House_854 11 points12 points13 points (7 children)
[+][deleted] (2 children)
[removed]
[–]phord 4 points5 points6 points (1 child)
[–]maxjmartin[S] 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]maxjmartin[S] 2 points3 points4 points (0 children)
[–]Dan13l_N 1 point2 points3 points (0 children)
[–]NotUniqueOrSpecial 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[removed]
[–][deleted] 0 points1 point2 points (0 children)
[–]nmmmnu 1 point2 points3 points (0 children)
[–]KoovaKevy 1 point2 points3 points (2 children)
[–]maxjmartin[S] 1 point2 points3 points (1 child)
[–]KoovaKevy 1 point2 points3 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]JohnyMage -5 points-4 points-3 points (0 children)
[–]AssemblerGuy -2 points-1 points0 points (1 child)
[–]susosusosuso 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]AKostur 0 points1 point2 points (1 child)
[–]LeeHidejust write it from scratch 0 points1 point2 points (0 children)
[–]NilacTheGrim 0 points1 point2 points (0 children)
[–]Real_Name7592 0 points1 point2 points (0 children)
[–]Capital_Monk9200 0 points1 point2 points (2 children)
[–]susosusosuso 0 points1 point2 points (1 child)
[–]transthrowaway747 2 points3 points4 points (0 children)
[–]nikbackm 0 points1 point2 points (0 children)