Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/client/plugin/compression.h" | 5 #include "remoting/client/plugin/compression.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 stream_.avail_in = size; | 22 stream_.avail_in = size; |
| 23 stream_.next_in = reinterpret_cast<Bytef*>(buffer); | 23 stream_.next_in = reinterpret_cast<Bytef*>(buffer); |
| 24 | 24 |
| 25 // Expand the internal buffer. | 25 // Expand the internal buffer. |
| 26 while (true) { | 26 while (true) { |
| 27 int last_size = buffer_.size(); | 27 int last_size = buffer_.size(); |
| 28 buffer_.resize(last_size + kZLIB_CHUNK); | 28 buffer_.resize(last_size + kZLIB_CHUNK); |
| 29 stream_.avail_out = kZLIB_CHUNK; | 29 stream_.avail_out = kZLIB_CHUNK; |
| 30 stream_.next_out = reinterpret_cast<Bytef*>(&buffer_[last_size]); | 30 stream_.next_out = reinterpret_cast<Bytef*>(&buffer_[last_size]); |
| 31 int ret = deflate(&stream_, flush); | 31 int ret = deflate(&stream_, flush); |
| 32 assert(ret != Z_STREAM_ERROR); | 32 |
| 33 // Check ret before the assert so that we don't get an unused variable | |
| 34 // warning in release builds. | |
| 35 if (ret == Z_STREAM_ERROR) { | |
| 36 assert(ret != Z_STREAM_ERROR); | |
|
Sergey Ulanov
2010/06/15 22:50:03
This should be replaced with DCHECK. I think, it w
| |
| 37 } | |
| 33 | 38 |
| 34 // Shrink the size of the vector. It doesn't alter the capacity. | 39 // Shrink the size of the vector. It doesn't alter the capacity. |
| 35 int compressed = kZLIB_CHUNK - stream_.avail_out; | 40 int compressed = kZLIB_CHUNK - stream_.avail_out; |
| 36 buffer_.resize(last_size + compressed); | 41 buffer_.resize(last_size + compressed); |
| 37 if (!compressed) | 42 if (!compressed) |
| 38 break; | 43 break; |
| 39 } | 44 } |
| 40 } | 45 } |
| 41 | 46 |
| 42 void ZCompressor::Write(char* buffer, int size) { | 47 void ZCompressor::Write(char* buffer, int size) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 void ZDecompressor::WriteInternal(char* buffer, int size, int flush) { | 79 void ZDecompressor::WriteInternal(char* buffer, int size, int flush) { |
| 75 stream_.avail_in = size; | 80 stream_.avail_in = size; |
| 76 stream_.next_in = reinterpret_cast<Bytef*>(buffer); | 81 stream_.next_in = reinterpret_cast<Bytef*>(buffer); |
| 77 | 82 |
| 78 while (true) { | 83 while (true) { |
| 79 int last_size = buffer_.size(); | 84 int last_size = buffer_.size(); |
| 80 buffer_.resize(last_size + kZLIB_CHUNK); | 85 buffer_.resize(last_size + kZLIB_CHUNK); |
| 81 stream_.avail_out = kZLIB_CHUNK; | 86 stream_.avail_out = kZLIB_CHUNK; |
| 82 stream_.next_out = reinterpret_cast<Bytef*>(&buffer_[last_size]); | 87 stream_.next_out = reinterpret_cast<Bytef*>(&buffer_[last_size]); |
| 83 int ret = inflate(&stream_, flush); | 88 int ret = inflate(&stream_, flush); |
| 84 assert(ret != Z_STREAM_ERROR); | 89 |
| 90 // Check ret before the assert so that we don't get an unused variable | |
| 91 // warning in release builds. | |
| 92 if (ret == Z_STREAM_ERROR) { | |
| 93 assert(ret != Z_STREAM_ERROR); | |
| 94 } | |
| 85 | 95 |
| 86 // Shrink the size of the vector. It doesn't alter the capacity. | 96 // Shrink the size of the vector. It doesn't alter the capacity. |
| 87 int decompressed = kZLIB_CHUNK - stream_.avail_out; | 97 int decompressed = kZLIB_CHUNK - stream_.avail_out; |
| 88 buffer_.resize(last_size + decompressed); | 98 buffer_.resize(last_size + decompressed); |
| 89 if (!decompressed) | 99 if (!decompressed) |
| 90 break; | 100 break; |
| 91 } | 101 } |
| 92 } | 102 } |
| 93 | 103 |
| 94 void ZDecompressor::Write(char* buffer, int size) { | 104 void ZDecompressor::Write(char* buffer, int size) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 106 int ZDecompressor::GetRawSize() { | 116 int ZDecompressor::GetRawSize() { |
| 107 return buffer_.size(); | 117 return buffer_.size(); |
| 108 } | 118 } |
| 109 | 119 |
| 110 int ZDecompressor::GetCompressedSize() { | 120 int ZDecompressor::GetCompressedSize() { |
| 111 // I don't care. | 121 // I don't care. |
| 112 return 0; | 122 return 0; |
| 113 } | 123 } |
| 114 | 124 |
| 115 } // namespace remoting | 125 } // namespace remoting |
| OLD | NEW |