@@ -41,22 +41,29 @@ public SingleLogicalResult<
4141 > BASE ;
4242
4343 Or_SingleLogicalResult_SingleLogicalResult ( const LHS_TYPE & lhs_, const RHS_TYPE & rhs_) :
44- lhs (lhs_) , rhs(rhs_){} ;
44+ lhs (lhs_.get_ref()) , rhs(rhs_.get_ref() ){} ;
4545
4646 inline void apply (){
4747 int left = lhs.get () ;
48- if ( Rcpp::traits::is_na<LGLSXP >( left ) ){
49- BASE::set ( left ) ;
50- } else if ( left == TRUE ){
48+ if ( left == TRUE ){
5149 BASE::set ( TRUE ) ;
50+ return ;
51+ }
52+
53+ // NA || TRUE is TRUE
54+ int right = rhs.get () ;
55+ if ( Rcpp::traits::is_na<LGLSXP >( left ) && right != TRUE ){
56+ BASE::set ( left ) ;
5257 } else {
53- BASE::set ( rhs. get () ) ;
58+ BASE::set ( right ) ;
5459 }
5560 }
5661
5762private:
58- const LHS_TYPE & lhs ;
59- const RHS_TYPE & rhs ;
63+ // by value, since these are usually temporaries, and non-const, since
64+ // evaluating them caches their result
65+ LHS_T lhs ;
66+ RHS_T rhs ;
6067
6168} ;
6269
@@ -77,7 +84,7 @@ public SingleLogicalResult<
7784 > BASE ;
7885
7986 Or_SingleLogicalResult_SingleLogicalResult ( const LHS_TYPE & lhs_, const RHS_TYPE & rhs_) :
80- lhs (lhs_) , rhs(rhs_){} ;
87+ lhs (lhs_.get_ref()) , rhs(rhs_.get_ref() ){} ;
8188
8289 inline void apply (){
8390 // here we know rhs does not have NA, so we start with the rhs
@@ -90,8 +97,8 @@ public SingleLogicalResult<
9097 }
9198
9299private:
93- const LHS_TYPE & lhs ;
94- const RHS_TYPE & rhs ;
100+ LHS_T lhs ;
101+ RHS_T rhs ;
95102
96103} ;
97104
@@ -113,7 +120,7 @@ public SingleLogicalResult<
113120 > BASE ;
114121
115122 Or_SingleLogicalResult_SingleLogicalResult ( const LHS_TYPE & lhs_, const RHS_TYPE & rhs_) :
116- lhs (lhs_) , rhs(rhs_){} ;
123+ lhs (lhs_.get_ref()) , rhs(rhs_.get_ref() ){} ;
117124
118125 inline void apply (){
119126 // here we know lhs does not have NA, so we start with the rhs
@@ -126,8 +133,8 @@ public SingleLogicalResult<
126133 }
127134
128135private:
129- const LHS_TYPE & lhs ;
130- const RHS_TYPE & rhs ;
136+ LHS_T lhs ;
137+ RHS_T rhs ;
131138
132139} ;
133140
@@ -148,7 +155,7 @@ public SingleLogicalResult<
148155 > BASE ;
149156
150157 Or_SingleLogicalResult_SingleLogicalResult ( const LHS_TYPE & lhs_, const RHS_TYPE & rhs_) :
151- lhs (lhs_) , rhs(rhs_){} ;
158+ lhs (lhs_.get_ref()) , rhs(rhs_.get_ref() ){} ;
152159
153160 inline void apply (){
154161 int left = lhs.get () ;
@@ -160,8 +167,8 @@ public SingleLogicalResult<
160167 }
161168
162169private:
163- const LHS_TYPE & lhs ;
164- const RHS_TYPE & rhs ;
170+ LHS_T lhs ;
171+ RHS_T rhs ;
165172
166173} ;
167174
@@ -170,7 +177,7 @@ template <bool LHS_NA, typename LHS_T>
170177class Or_SingleLogicalResult_bool :
171178public SingleLogicalResult<
172179 LHS_NA ,
173- And_SingleLogicalResult_bool <LHS_NA ,LHS_T >
180+ Or_SingleLogicalResult_bool <LHS_NA ,LHS_T >
174181 >
175182{
176183public:
@@ -181,7 +188,7 @@ public SingleLogicalResult<
181188 > BASE ;
182189
183190 Or_SingleLogicalResult_bool ( const LHS_TYPE & lhs_, bool rhs_) :
184- lhs (lhs_), rhs(rhs_){} ;
191+ lhs (lhs_.get_ref() ), rhs(rhs_){} ;
185192
186193 inline void apply (){
187194 if ( rhs ){
@@ -192,7 +199,7 @@ public SingleLogicalResult<
192199 }
193200
194201private:
195- const LHS_TYPE & lhs ;
202+ LHS_T lhs ;
196203 bool rhs ;
197204
198205} ;
@@ -298,7 +305,7 @@ template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T>
298305inline Rcpp::sugar::Or_SingleLogicalResult_SingleLogicalResult<LHS_NA ,LHS_T ,RHS_NA ,RHS_T >
299306operator ||(
300307 const Rcpp::sugar::SingleLogicalResult<LHS_NA ,LHS_T >& lhs,
301- const Rcpp::sugar::SingleLogicalResult<LHS_NA , LHS_T >& rhs
308+ const Rcpp::sugar::SingleLogicalResult<RHS_NA , RHS_T >& rhs
302309){
303310 return Rcpp::sugar::Or_SingleLogicalResult_SingleLogicalResult<LHS_NA ,LHS_T ,RHS_NA ,RHS_T >( lhs, rhs ) ;
304311}
0 commit comments