comparison liboctave/Array.cc @ 8580:188d38a553c7

further indexing optimization touches
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 23 Jan 2009 13:13:39 +0100
parents 3a3421a9f0bb
children ea8e65ca234f
comparison
equal deleted inserted replaced
8579:7e0f36dfefbe 8580:188d38a553c7
1214 { 1214 {
1215 octave_idx_type nx = i.extent (n); 1215 octave_idx_type nx = i.extent (n);
1216 // Try to resize first if necessary. 1216 // Try to resize first if necessary.
1217 if (nx != n) 1217 if (nx != n)
1218 { 1218 {
1219 // A simple optimization. Things like A(1:N) = x will skip fill on 1219 // Optimize case A = []; A(1:n) = X with A empty.
1220 // resizing, if A is 0x0.
1221 if (rows () == 0 && columns () == 0 && ndims () == 2 1220 if (rows () == 0 && columns () == 0 && ndims () == 2
1222 && rhl == 1 && i.is_colon_equiv (nx)) 1221 && i.is_colon_equiv (nx))
1223 *this = Array<T> (dim_vector (1, nx)); 1222 {
1224 else 1223 if (rhl == 1)
1225 resize_fill (nx, rfv); 1224 *this = Array<T> (dim_vector (1, nx), rhs(0));
1225 else
1226 *this = Array<T> (rhs, dim_vector (1, nx));
1227 return;
1228 }
1229
1230 resize_fill (nx, rfv);
1226 n = numel (); 1231 n = numel ();
1227 } 1232 }
1228 1233
1229 // If the resizing was ambiguous, resize has already griped. 1234 // If the resizing was ambiguous, resize has already griped.
1230 if (nx == n) 1235 if (nx == n)
1282 if (match) 1287 if (match)
1283 { 1288 {
1284 // Resize if requested. 1289 // Resize if requested.
1285 if (rdv != dv) 1290 if (rdv != dv)
1286 { 1291 {
1292 // Optimize case A = []; A(1:m, 1:n) = X
1293 if (dv.all_zero () && i.is_colon_equiv (rdv(0))
1294 && j.is_colon_equiv (rdv(1)))
1295 {
1296 if (isfill)
1297 *this = Array<T> (rdv, rhs(0));
1298 else
1299 *this = Array<T> (rhs, rdv);
1300 return;
1301 }
1302
1287 resize (rdv, rfv); 1303 resize (rdv, rfv);
1288 dv = dimensions; 1304 dv = dimensions;
1289 } 1305 }
1290 1306
1291 // If the resizing was invalid, resize has already griped. 1307 // If the resizing was invalid, resize has already griped.