Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/4.0.3/HeuristicLab.EPPlus-4.0.3/epplus-4.0.3 memory improvement.diff @ 12179

Last change on this file since 12179 was 12179, checked in by abeham, 9 years ago

#2341:

  • Added patch file containing differences to 4.0.3 vanilla
  • Removed EPPlus-3.1.3 from ExtLibs
File size: 10.1 KB
  • EPPlus-4.0.3/ExcelCellBase.cs

    diff --git a/EPPlus-4.0.3/ExcelCellBase.cs b/EPPlus-4.0.3/ExcelCellBase.cs
    a b  
    480480            bool fixedRow, fixedCol;
    481481            return GetRowCol(address, out row, out col, throwException, out fixedRow, out fixedCol);
    482482        }
    483         internal static bool GetRowCol(string address, out int row, out int col, bool throwException, out bool fixedRow, out bool fixedCol)
    484         {
     483        internal static bool GetRowCol(string address, out int row, out int col, bool throwException, out bool fixedRow, out bool fixedCol) {
    485484            bool colPart = true;
    486             string sRow = "", sCol = "";
     485            int colStartIx = 0;
     486            int colLength = 0;
    487487            col = 0;
     488            row = 0;
    488489            fixedRow = false;
    489490            fixedCol = false;
    490             if (address.IndexOf(':') > 0)  //If it is a mult-cell address use
    491             {
    492                 address = address.Substring(0, address.IndexOf(':'));
    493             }
     491
    494492            if (address.EndsWith("#REF!"))
    495493            {
    496494                row = 0;
     
    501499            int sheetMarkerIndex = address.IndexOf('!');
    502500            if (sheetMarkerIndex >= 0)
    503501            {
    504                 address = address.Substring(sheetMarkerIndex + 1);
     502                colStartIx = sheetMarkerIndex + 1;
    505503            }
    506504
    507             address = address.ToUpper(CultureInfo.InvariantCulture);
    508             for (int i = 0; i < address.Length; i++)
     505            for (int i = colStartIx; i < address.Length; i++)
    509506            {
    510                 if ((address[i] >= 'A' && address[i] <= 'Z') && colPart && sCol.Length <= 3)
     507                char c = address[i];
     508                if (colPart && ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) && colLength <= 3)
    511509                {
    512                     sCol += address[i];
     510                    col *= 26;
     511                    col += ((int)c) - 64;
     512                    colLength++;
    513513                }
    514                 else if (address[i] >= '0' && address[i] <= '9')
     514                else if (c >= '0' && c <= '9')
    515515                {
    516                     sRow += address[i];
     516                    row *= 10;
     517                    row += ((int)c) - 48;
    517518                    colPart = false;
    518519                }
    519                 else if (address[i] == '$')
     520                else if (c == '$')
    520521                {
    521                     if (i == 0)
    522                         fixedCol = true;
    523                     else
     522                    if (i == colStartIx)
     523                    {
     524                        colStartIx++;
     525                        fixedCol = true;
     526                    }
     527                    else
     528                    {
     529                        colPart = false;
    524530                        fixedRow = true;
     531                    }
     532                }
     533                else if (c == ':')
     534                {
     535                    break;
    525536                }
    526537                else
    527538                {
     539                    row = 0;
     540                    col = 0;
    528541                    if (throwException)
    529542                    {
    530543                        throw (new Exception(string.Format("Invalid Address format {0}", address)));
    531544                    }
    532545                    else
    533546                    {
    534                         row = 0;
    535                         col = 0;
    536547                        return false;
    537548                    }
    538549                }
    539550            }
    540 
    541             // Get the column number
    542             if (sCol != "")
    543             {
    544                 col = GetColumn(sCol);
    545             }
    546             else
    547             {
    548                 col = 0;
    549                 int.TryParse(sRow, out row);
    550                 return row>0;
    551             }
    552             // Get the row number
    553             if (sRow == "") //Blank, fullRow
    554             {
    555                 //if (throwException)
    556                 //{
    557                 //    throw (new Exception(string.Format("Invalid Address format {0}", address)));
    558                 //}
    559                 //else
    560                 //{                   
    561                 row = 0;
    562                 return col > 0;
    563                 //}
    564             }
    565             else
    566             {
    567                 return int.TryParse(sRow, out row);
    568             }
     551            return row != 0 || col != 0;
    569552        }
    570553
    571554        private static int GetColumn(string sCol)
  • EPPlus-4.0.3/ExcelRangeBase.cs

    diff --git a/EPPlus-4.0.3/ExcelRangeBase.cs b/EPPlus-4.0.3/ExcelRangeBase.cs
    a b  
    5858    /// <summary>
    5959  /// A range of cells
    6060  /// </summary>
    61   public class ExcelRangeBase : ExcelAddress, IExcelCell, IDisposable, IEnumerable<ExcelRangeBase>, IEnumerator<ExcelRangeBase>
     61  public class ExcelRangeBase : ExcelAddress, IExcelCell, IEnumerable<ExcelRangeBase>
    6262  {
    6363    /// <summary>
    6464    /// Reference to the worksheet
     
    27572757        CellsStoreEnumerator<object> cellEnum;
    27582758    public IEnumerator<ExcelRangeBase> GetEnumerator()
    27592759    {
    2760       Reset();
    2761       return this;
     2760            return new ExcelRangeBaseEnumerator(this);
    27622761    }
    27632762
    27642763    IEnumerator IEnumerable.GetEnumerator()
    27652764    {
    2766       Reset();
    2767       return this;
     2765            return new ExcelRangeBaseEnumerator(this);
    27682766    }
    27692767
    27702768    /// <summary>
    27712769    /// The current range when enumerating
    27722770    /// </summary>
    2773     public ExcelRangeBase Current
    2774     {
    2775       get
    2776       {
    2777         return new ExcelRangeBase(_worksheet, ExcelAddressBase.GetAddress(cellEnum.Row, cellEnum.Column));
    2778       }
    2779     }
     2771        public class ExcelRangeBaseEnumerator : IEnumerator<ExcelRangeBase> {
     2772            private CellsStoreEnumerator<object> _cellEnum;
     2773            private int _enumAddressIx = -1;
     2774            private ExcelRangeBase _range;
     2775            private ExcelRangeBase _current;
    27802776
    2781     /// <summary>
    2782     /// The current range when enumerating
    2783     /// </summary>
    2784     object IEnumerator.Current
    2785     {
    2786       get
    2787       {
    2788         return ((object)(new ExcelRangeBase(_worksheet, ExcelAddressBase.GetAddress(cellEnum.Row, cellEnum.Column))));
    2789       }
    2790     }
    2791 
    2792     int _enumAddressIx = -1;
    2793         public bool MoveNext()
    2794     {
    2795             if (cellEnum.Next())
    2796             {
    2797                 return true;
    2798             }
    2799             else if (_addresses!=null)
    2800             {
    2801                 _enumAddressIx++;
    2802                 if (_enumAddressIx < _addresses.Count)
    2803                 {
    2804                     cellEnum = new CellsStoreEnumerator<object>(_worksheet._values,
    2805                         _addresses[_enumAddressIx]._fromRow,
    2806                         _addresses[_enumAddressIx]._fromCol,
    2807                         _addresses[_enumAddressIx]._toRow,
    2808                         _addresses[_enumAddressIx]._toCol);
    2809                     return MoveNext();
    2810                 }
    2811                 else
    2812                 {
    2813                     return false;
     2777            /// <summary>
     2778            /// The current range when enumerating
     2779            /// </summary>
     2780            public ExcelRangeBase Current {
     2781                get {
     2782                    return _current;
    28142783                }
    28152784            }
    2816             return false;
    2817     }
    28182785
    2819     public void Reset()
    2820     {
    2821             _enumAddressIx = -1;
    2822             cellEnum = new CellsStoreEnumerator<object>(_worksheet._values, _fromRow, _fromCol, _toRow, _toCol);
     2786            /// <summary>
     2787            /// The current range when enumerating
     2788            /// </summary>
     2789            object IEnumerator.Current {
     2790                get {
     2791                    return _current;
     2792                }
     2793            }
     2794
     2795            public ExcelRangeBaseEnumerator(ExcelRangeBase range) {
     2796                this._range = range;
     2797                Reset();
     2798            }
     2799            public bool MoveNext() {
     2800                if (_cellEnum.Next()) {
     2801                    _current._fromCol = _cellEnum.Column;
     2802                    _current._fromRow = _cellEnum.Row;
     2803                    _current._toCol = _cellEnum.Column;
     2804                    _current._toRow = _cellEnum.Row;
     2805                    _current.Address = GetAddress(_current._fromRow, _current._fromCol);
     2806                    return true;
     2807                }
     2808                else if (_range._addresses != null) {
     2809                    _enumAddressIx++;
     2810                    if (_enumAddressIx < _range._addresses.Count) {
     2811                        _cellEnum = new CellsStoreEnumerator<object>(_range._worksheet._values,
     2812                            _range._addresses[_enumAddressIx]._fromRow,
     2813                            _range._addresses[_enumAddressIx]._fromCol,
     2814                            _range._addresses[_enumAddressIx]._toRow,
     2815                            _range._addresses[_enumAddressIx]._toCol);
     2816                        return MoveNext();
     2817                    }
     2818                    else {
     2819                        return false;
     2820                    }
     2821                }
     2822                return false;
     2823            }
     2824
     2825            public void Reset() {
     2826                _enumAddressIx = -1;
     2827                _cellEnum = new CellsStoreEnumerator<object>(_range._worksheet._values, _range._fromRow, _range._fromCol, _range._toRow, _range._toCol);
     2828                _current = new ExcelRangeBase(_range._worksheet, ExcelAddressBase.GetAddress(_cellEnum.Row, _cellEnum.Column));
     2829            }
     2830
     2831            public void Dispose() {
     2832                if (_cellEnum != null) {
     2833                    _cellEnum.Dispose();
     2834                    _cellEnum = null;
     2835                }
     2836            }
     2837
    28232838        }
    28242839
    28252840        //private void GetNextIndexEnum(int fromRow, int fromCol, int toRow, int toCol)
  • EPPlus-4.0.3/Table/PivotTable/ExcelPivotTable.cs

    diff --git a/EPPlus-4.0.3/Table/PivotTable/ExcelPivotTable.cs b/EPPlus-4.0.3/Table/PivotTable/ExcelPivotTable.cs
    a b  
    150150
    151151            LoadFields();
    152152
    153             using (var r=sheet.Cells[address.Address])
    154             {
    155                 r.Clear();
    156             }
     153            sheet.Cells[address.Address].Clear();
    157154        }
    158155        private void init()
    159156        {
Note: See TracBrowser for help on using the repository browser.