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

Unified Diff: src/utils/SkHashDigest.h

Issue 14265010: Make SkSHA1 and SkM5 use common SkDigestHash result type (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: rename_set_to_copyFrom Created 7 years, 8 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
« no previous file with comments | « src/utils/SkBitmapHasher.cpp ('k') | src/utils/SkMD5.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkHashDigest.h
===================================================================
--- src/utils/SkHashDigest.h (revision 0)
+++ src/utils/SkHashDigest.h (revision 0)
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkHashDigest_DEFINED
+#define SkHashDigest_DEFINED
+
+#include "SkData.h"
+
+/**
+ * A mutable hash digest; it can be filled with a bytearray of any
+ * length, anytime.
+ */
+class SkHashDigest {
+public:
+ SkHashDigest() : fSkDataPtr(SkData::NewEmpty()) {}
+ SkHashDigest(const void *data, size_t length) : fSkDataPtr(SkData::NewWithCopy(data, length)) {}
+
+ /**
+ * Destructor: if this object is the only one with a reference to the data
+ * that makes up the hash digest, then that data will be freed.
+ */
+ ~SkHashDigest() {
+ SkSafeUnref(fSkDataPtr);
+ }
+
+ /**
+ * Replace the hash digest data held by this object with a copy of the
+ * data from this pointer/length.
+ */
+ void copyFrom(void *data, size_t length) {
epoger 2013/04/15 19:17:03 patchset 2: renamed SkHashDigest::set() to SkHashD
+ fSkDataPtr->unref();
+ fSkDataPtr = SkData::NewWithCopy(data, length);
+ }
+
+ /**
+ * Return a pointer to the SkData object holding the hash digest data.
+ *
+ * The SkData object's reference counter will be bumped to account for this call,
+ * so the caller must call unref() on it once it is no longer needed!
+ *
+ * For example:
+ * {
+ * SkData *skDataPtr = digest.skDataPtr();
+ * const uint8_t* bytes = skDataPtr->bytes();
+ * ...
+ * skDataPtr->unref();
+ * }
+ */
+ SkData *skDataPtr() const {
+ fSkDataPtr->ref();
+ return fSkDataPtr;
+ }
+
+ size_t size() const {
+ return fSkDataPtr->size();
+ }
+
+ bool equals(const SkHashDigest &other) const {
+ return fSkDataPtr->equals(other.fSkDataPtr);
+ }
+
+private:
+
+ // fSkDataPtr may change over the lifetime of the SkHashDigest object,
+ // but it will never be set to NULL.
+ // (Every SkHashDigest constructor initializes it to point at *some* SkData object.)
+ SkData *fSkDataPtr;
+};
+
+#endif
« no previous file with comments | « src/utils/SkBitmapHasher.cpp ('k') | src/utils/SkMD5.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698