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

Unified Diff: chrome/browser/sync/notifier/base/fastalloc.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/notifier/base/fastalloc.h
===================================================================
--- chrome/browser/sync/notifier/base/fastalloc.h (revision 0)
+++ chrome/browser/sync/notifier/base/fastalloc.h (revision 0)
@@ -0,0 +1,59 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_NOTIFIER_BASE_FASTALLOC_H_
+#define CHROME_BROWSER_SYNC_NOTIFIER_BASE_FASTALLOC_H_
+
+#include <assert.h>
+
+namespace notifier {
+
+template<class T, size_t Size>
+class FastAlloc {
+ public:
+ FastAlloc() : buffer_(NULL), size_(0) { };
+ ~FastAlloc() { freeBuffer(); }
+ T* get_buffer(size_t size) {
+ if (size_ != 0) {
+ // We only allow one call to get_buffer. This makes the logic here
+ // simpler, and the user has to worry less about someone else calling
+ // get_buffer again on the same FastAlloc object and invalidating the
+ // memory they were using.
+ assert(false && "get_buffer may one be called once");
+ return NULL;
+ }
+
+ if (size <= Size) {
+ buffer_ = internal_buffer_;
+ } else {
+ buffer_ = new T[size];
+ }
+
+ if (buffer_ != NULL) {
+ size_ = size;
+ }
+ return buffer_;
+ }
+
+ private:
+ void freeBuffer() {
+#ifdef DEBUG
+ memset(buffer_, 0xCC, size_ * sizeof(T));
+#endif
+
+ if (buffer_ != NULL && buffer_ != internal_buffer_) {
+ delete[] buffer_;
+ }
+ buffer_ = NULL;
+ size_ = 0;
+ }
+
+ T* buffer_;
+ T internal_buffer_[Size];
+ size_t size_;
+};
+
+}
+
+#endif // CHROME_BROWSER_SYNC_NOTIFIER_BASE_FASTALLOC_H_
Property changes on: chrome\browser\sync\notifier\base\fastalloc.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698