comparison src/ov-cell.cc @ 8815:af907aeedbf4

cache cellstr_value in ov-cell
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 19 Feb 2009 16:37:17 +0100
parents 3ef774603887
children 3efa512a0957
comparison
equal deleted inserted replaced
8814:de16ebeef93d 8815:af907aeedbf4
212 212
213 int n = type.length (); 213 int n = type.length ();
214 214
215 octave_value t_rhs = rhs; 215 octave_value t_rhs = rhs;
216 216
217 clear_cellstr_cache ();
218
217 if (n > 1) 219 if (n > 1)
218 { 220 {
219 switch (type[0]) 221 switch (type[0])
220 { 222 {
221 case '(': 223 case '(':
374 } 376 }
375 377
376 return retval; 378 return retval;
377 } 379 }
378 380
381 void
382 octave_cell::clear_cellstr_cache (void) const
383 {
384 cellstr_cache = Array<std::string> ();
385 }
386
387 void
388 octave_cell::make_cellstr_cache (void) const
389 {
390 cellstr_cache = Array<std::string> (matrix.dims ());
391
392 octave_idx_type n = numel ();
393
394 std::string *dst = cellstr_cache.fortran_vec ();
395 const octave_value *src = matrix.data ();
396
397 for (octave_idx_type i = 0; i < n; i++)
398 dst[i] = src[i].string_value ();
399 }
400
401 bool
402 octave_cell::is_cellstr (void) const
403 {
404 bool retval;
405 if (! cellstr_cache.is_empty ())
406 retval = true;
407 else
408 {
409 retval = matrix.is_cellstr ();
410 // force cache to be created here
411 if (retval)
412 make_cellstr_cache ();
413 }
414
415 return retval;
416 }
417
418 void
419 octave_cell::assign (const octave_value_list& idx, const Cell& rhs)
420 {
421 clear_cellstr_cache ();
422 octave_base_matrix<Cell>::assign (idx, rhs);
423 }
424
425 void
426 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs)
427 {
428 clear_cellstr_cache ();
429 octave_base_matrix<Cell>::assign (idx, rhs);
430 }
431
432
433 void
434 octave_cell::delete_elements (const octave_value_list& idx)
435 {
436 clear_cellstr_cache ();
437 octave_base_matrix<Cell>::delete_elements (idx);
438 }
439
379 size_t 440 size_t
380 octave_cell::byte_size (void) const 441 octave_cell::byte_size (void) const
381 { 442 {
382 size_t retval = 0; 443 size_t retval = 0;
383 444
513 } 574 }
514 575
515 Array<std::string> 576 Array<std::string>
516 octave_cell::cellstr_value (void) const 577 octave_cell::cellstr_value (void) const
517 { 578 {
518 Array<std::string> retval (dims ()); 579 Array<std::string> retval;
519 580
520 if (is_cellstr ()) 581 if (is_cellstr ())
521 { 582 {
522 octave_idx_type n = numel (); 583 retval = cellstr_cache;
523
524 std::string *dst = retval.fortran_vec ();
525 const octave_value *src = matrix.data ();
526
527 for (octave_idx_type i = 0; i < n; i++)
528 dst[i] = src[i].string_value ();
529 } 584 }
530 else 585 else
531 error ("invalid conversion from cell array to Array<std::string>"); 586 error ("invalid conversion from cell array to array of strings");
532 587
533 return retval; 588 return retval;
534 } 589 }
535 590
536 bool 591 bool
659 714
660 bool 715 bool
661 octave_cell::load_ascii (std::istream& is) 716 octave_cell::load_ascii (std::istream& is)
662 { 717 {
663 bool success = true; 718 bool success = true;
719
720 clear_cellstr_cache ();
664 721
665 string_vector keywords(2); 722 string_vector keywords(2);
666 723
667 keywords[0] = "ndims"; 724 keywords[0] = "ndims";
668 keywords[1] = "rows"; 725 keywords[1] = "rows";
824 return true; 881 return true;
825 } 882 }
826 883
827 bool 884 bool
828 octave_cell::load_binary (std::istream& is, bool swap, 885 octave_cell::load_binary (std::istream& is, bool swap,
829 oct_mach_info::float_format fmt) 886 oct_mach_info::float_format fmt)
830 { 887 {
888 clear_cellstr_cache ();
889
831 bool success = true; 890 bool success = true;
832 int32_t mdims; 891 int32_t mdims;
833 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) 892 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
834 return false; 893 return false;
835 if (swap) 894 if (swap)
898 } 957 }
899 958
900 return success; 959 return success;
901 } 960 }
902 961
962 void *
963 octave_cell::mex_get_data (void) const
964 {
965 clear_cellstr_cache ();
966 return matrix.mex_get_data ();
967 }
968
903 #if defined (HAVE_HDF5) 969 #if defined (HAVE_HDF5)
904 970
905 bool 971 bool
906 octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) 972 octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
907 { 973 {
984 1050
985 bool 1051 bool
986 octave_cell::load_hdf5 (hid_t loc_id, const char *name, 1052 octave_cell::load_hdf5 (hid_t loc_id, const char *name,
987 bool have_h5giterate_bug) 1053 bool have_h5giterate_bug)
988 { 1054 {
1055 clear_cellstr_cache ();
1056
989 bool retval = false; 1057 bool retval = false;
990 1058
991 dim_vector dv; 1059 dim_vector dv;
992 int empty = load_hdf5_empty (loc_id, name, dv); 1060 int empty = load_hdf5_empty (loc_id, name, dv);
993 if (empty > 0) 1061 if (empty > 0)