You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2016/05/11 20:31:28 UTC

[trafficserver] 04/33: TS-4425: Rename Ptr::_ptr() to Ptr::get().

This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 464d5be166162b3db99ff4e05521766c9640a42f
Author: James Peach <jp...@apache.org>
AuthorDate: Wed May 4 22:30:37 2016 -0700

    TS-4425: Rename Ptr::_ptr() to Ptr::get().
    
    Ptr::get() is the conventional name to extract a raw pointer from
    a smart pointer. Also introduce Ptr::object() which type-erases the
    pointer to a RefCountObject*.
---
 iocore/cache/Cache.cc      |  2 +-
 iocore/cache/CacheRead.cc  |  2 +-
 iocore/cache/CacheVol.cc   |  2 +-
 iocore/cache/CacheWrite.cc |  2 +-
 lib/ts/Ptr.h               | 41 +++++++++++++++++++++++++----------------
 proxy/hdrs/HdrHeap.cc      |  2 +-
 6 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 8d13438..cf4b569 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -2203,7 +2203,7 @@ unmarshal_helper(Doc *doc, Ptr<IOBufferData> &buf, int &okay)
   char *tmp = doc->hdr();
   int len = doc->hlen;
   while (len > 0) {
-    int r = HTTPInfo::unmarshal(tmp, len, buf._ptr());
+    int r = HTTPInfo::unmarshal(tmp, len, buf.get());
     if (r < 0) {
       ink_assert(!"CacheVC::handleReadDone unmarshal failed");
       okay = 0;
diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index 3e98ba9..685426a 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -410,7 +410,7 @@ CacheVC::openReadFromWriter(int event, Event *e)
       // Update case (b) : grab doc_len from the writer's alternate
       doc_len = alternate.object_size_get();
       if (write_vc->update_key == cod->single_doc_key && (cod->move_resident_alt || write_vc->f.rewrite_resident_alt) &&
-          write_vc->first_buf._ptr()) {
+          write_vc->first_buf.get()) {
         // the resident alternate is being updated and its a
         // header only update. The first_buf of the writer has the
         // document body.
diff --git a/iocore/cache/CacheVol.cc b/iocore/cache/CacheVol.cc
index b308bfe..09b7b8e 100644
--- a/iocore/cache/CacheVol.cc
+++ b/iocore/cache/CacheVol.cc
@@ -239,7 +239,7 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
       char *tmp = doc->hdr();
       int len = doc->hlen;
       while (len > 0) {
-        int r = HTTPInfo::unmarshal(tmp, len, buf._ptr());
+        int r = HTTPInfo::unmarshal(tmp, len, buf.get());
         if (r < 0) {
           ink_assert(!"CacheVC::scanObject unmarshal failed");
           goto Lskip;
diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc
index dfb927c..cd56a5b 100644
--- a/iocore/cache/CacheWrite.cc
+++ b/iocore/cache/CacheWrite.cc
@@ -106,7 +106,7 @@ CacheVC::updateVector(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
       alternate_index = write_vector->insert(&alternate, alternate_index);
     }
 
-    if (od->move_resident_alt && first_buf._ptr() && !od->has_multiple_writers()) {
+    if (od->move_resident_alt && first_buf.get() && !od->has_multiple_writers()) {
       Doc *doc = (Doc *)first_buf->data();
       int small_doc = (int64_t)doc->data_len() < (int64_t)cache_config_alt_rewrite_max_size;
       int have_res_alt = doc->key == od->single_doc_key;
diff --git a/lib/ts/Ptr.h b/lib/ts/Ptr.h
index dd87657..56fc4cb 100644
--- a/lib/ts/Ptr.h
+++ b/lib/ts/Ptr.h
@@ -136,10 +136,19 @@ public:
     return (m_ptr != p.m_ptr);
   }
 
+  // Return the raw pointer.
+  T *
+  get() const
+  {
+    return m_ptr;
+  }
+
+  // Return the raw pointer as a RefCount object. Typically
+  // this is for keeping a collection of heterogenous objects.
   RefCountObj *
-  _ptr()
+  object() const
   {
-    return (RefCountObj *)m_ptr;
+    return static_cast<RefCountObj *>(m_ptr);
   }
 
   T *m_ptr;
@@ -159,24 +168,23 @@ make_ptr(T *p)
 ////////////////////////////////////////////////////////////////////////
 template <class T> inline Ptr<T>::Ptr(T *ptr /* = 0 */) : m_ptr(ptr)
 {
-  if (m_ptr)
-    _ptr()->refcount_inc();
-  return;
+  if (m_ptr) {
+    m_ptr->refcount_inc();
+  }
 }
 
 template <class T> inline Ptr<T>::Ptr(const Ptr<T> &src) : m_ptr(src.m_ptr)
 {
-  if (m_ptr)
-    _ptr()->refcount_inc();
-  return;
+  if (m_ptr) {
+    m_ptr->refcount_inc();
+  }
 }
 
 template <class T> inline Ptr<T>::~Ptr()
 {
-  if ((m_ptr) && _ptr()->refcount_dec() == 0) {
-    _ptr()->free();
+  if (m_ptr && m_ptr->refcount_dec() == 0) {
+    m_ptr->free();
   }
-  return;
 }
 
 template <class T>
@@ -185,17 +193,18 @@ Ptr<T>::operator=(T *p)
 {
   T *temp_ptr = m_ptr;
 
-  if (m_ptr == p)
+  if (m_ptr == p) {
     return (*this);
+  }
 
   m_ptr = p;
 
-  if (m_ptr != 0) {
-    _ptr()->refcount_inc();
+  if (m_ptr) {
+    m_ptr->refcount_inc();
   }
 
-  if ((temp_ptr) && ((RefCountObj *)temp_ptr)->refcount_dec() == 0) {
-    ((RefCountObj *)temp_ptr)->free();
+  if (temp_ptr && temp_ptr->refcount_dec() == 0) {
+    temp_ptr->free();
   }
 
   return (*this);
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 28dd399..9f01e19 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -972,7 +972,7 @@ HdrHeap::attach_str_heap(char *h_start, int h_len, RefCountObj *h_ref_obj, int *
   // Loop over existing entries to see if this one is already present
   for (int z = 0; z < *index; z++) {
     if (m_ronly_heap[z].m_heap_start == h_start) {
-      ink_assert(m_ronly_heap[z].m_ref_count_ptr._ptr() == h_ref_obj);
+      ink_assert(m_ronly_heap[z].m_ref_count_ptr.object() == h_ref_obj);
 
       // The lengths could be different because our copy could be
       //   read-only and the copy we are attaching from could be

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.