Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: runtime/bin/filter.h

Issue 12812006: Avoid massive stack frames by allocating 64k buffers in the heap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allocate buffer as part of filter and fix code style Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef BIN_FILTER_H_ 5 #ifndef BIN_FILTER_H_
6 #define BIN_FILTER_H_ 6 #define BIN_FILTER_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
11 #include "../third_party/zlib/zlib.h" 11 #include "../third_party/zlib/zlib.h"
12 12
13 class Filter { 13 class Filter {
14 protected:
15 Filter() : initialized(false) {}
16
17 public: 14 public:
18 virtual ~Filter() {} 15 virtual ~Filter() {}
19 16
20 public:
21 virtual bool Init() = 0; 17 virtual bool Init() = 0;
18
22 /** 19 /**
23 * On a succesfull call to Process, Process will take ownership of data. On 20 * On a succesfull call to Process, Process will take ownership of data. On
24 * successive calls to either Processed or ~Filter, data will be freed with 21 * successive calls to either Processed or ~Filter, data will be freed with
25 * a delete[] call. 22 * a delete[] call.
26 */ 23 */
27 virtual bool Process(uint8_t* data, intptr_t length) = 0; 24 virtual bool Process(uint8_t* data, intptr_t length) = 0;
28 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish) = 0; 25 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish) = 0;
29 26
30
31 public:
32 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter, 27 static Dart_Handle SetFilterPointerNativeField(Dart_Handle filter,
33 Filter* filter_pointer); 28 Filter* filter_pointer);
34 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter, 29 static Dart_Handle GetFilterPointerNativeField(Dart_Handle filter,
35 Filter** filter_pointer); 30 Filter** filter_pointer);
36 31
32 bool initialized() const { return initialized_; }
33 void set_initialized(bool value) { initialized_ = value; }
34 uint8_t* processed_buffer() { return processed_buffer_; }
35 intptr_t processed_buffer_size() const { return kFilterBufferSize; }
36
37 protected: 37 protected:
38 bool initialized; 38 Filter() : initialized_(false) {}
39
40 private:
41 static const intptr_t kFilterBufferSize = 64 * KB;
42 uint8_t processed_buffer_[kFilterBufferSize];
43 bool initialized_;
44
45 DISALLOW_COPY_AND_ASSIGN(Filter);
39 }; 46 };
40 47
41 class ZLibDeflateFilter : public Filter { 48 class ZLibDeflateFilter : public Filter {
42 public: 49 public:
43 ZLibDeflateFilter(bool gZip = false, int level = 6) 50 ZLibDeflateFilter(bool gzip = false, int level = 6)
44 : gZip(gZip), level(level), current_buffer(NULL) {} 51 : gzip_(gzip), level_(level), current_buffer_(NULL) {}
45 virtual ~ZLibDeflateFilter(); 52 virtual ~ZLibDeflateFilter();
46 53
47 public:
48 virtual bool Init(); 54 virtual bool Init();
49 virtual bool Process(uint8_t* data, intptr_t length); 55 virtual bool Process(uint8_t* data, intptr_t length);
50 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); 56 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish);
51 57
52 private: 58 private:
53 const bool gZip; 59 const bool gzip_;
54 const int level; 60 const int level_;
55 uint8_t* current_buffer; 61 uint8_t* current_buffer_;
56 z_stream stream; 62 z_stream stream_;
63
64 DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter);
57 }; 65 };
58 66
59 class ZLibInflateFilter : public Filter { 67 class ZLibInflateFilter : public Filter {
60 public: 68 public:
61 ZLibInflateFilter() : current_buffer(NULL) {} 69 ZLibInflateFilter() : current_buffer_(NULL) {}
62 virtual ~ZLibInflateFilter(); 70 virtual ~ZLibInflateFilter();
63 71
64 public:
65 virtual bool Init(); 72 virtual bool Init();
66 virtual bool Process(uint8_t* data, intptr_t length); 73 virtual bool Process(uint8_t* data, intptr_t length);
67 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish); 74 virtual intptr_t Processed(uint8_t* buffer, intptr_t length, bool finish);
68 75
69 private: 76 private:
70 uint8_t* current_buffer; 77 uint8_t* current_buffer_;
71 z_stream stream; 78 z_stream stream_;
79
80 DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter);
72 }; 81 };
73 82
74 #endif // BIN_FILTER_H_ 83 #endif // BIN_FILTER_H_
75 84
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698