当前位置: 首页>>代码示例>>C++>>正文


C++ LIKELY函数代码示例

本文整理汇总了C++中LIKELY函数的典型用法代码示例。如果您正苦于以下问题:C++ LIKELY函数的具体用法?C++ LIKELY怎么用?C++ LIKELY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LIKELY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initThread

 // Reallocates a chunk. We can save on a new allocation if the new requested
 // size still fits in the chunk.
 void *reallocate(void *OldPtr, uptr NewSize) {
   if (UNLIKELY(!ThreadInited))
     initThread();
   UnpackedHeader OldHeader;
   uptr Size = getUsableSize(OldPtr, &OldHeader);
   uptr ChunkBeg = reinterpret_cast<uptr>(OldPtr);
   ScudoChunk *Chunk =
       reinterpret_cast<ScudoChunk *>(ChunkBeg - ChunkHeaderSize);
   if (OldHeader.AllocType != FromMalloc) {
     dieWithMessage("ERROR: invalid chunk type when reallocating address %p\n",
                    Chunk);
   }
   UnpackedHeader NewHeader = OldHeader;
   // The new size still fits in the current chunk.
   if (NewSize <= Size) {
     NewHeader.RequestedSize = NewSize;
     Chunk->compareExchangeHeader(&NewHeader, &OldHeader);
     return OldPtr;
   }
   // Otherwise, we have to allocate a new chunk and copy the contents of the
   // old one.
   void *NewPtr = allocate(NewSize, MinAlignment, FromMalloc);
   if (NewPtr) {
     uptr OldSize = OldHeader.RequestedSize;
     memcpy(NewPtr, OldPtr, Min(NewSize, OldSize));
     NewHeader.State = ChunkQuarantine;
     Chunk->compareExchangeHeader(&NewHeader, &OldHeader);
     if (LIKELY(!ThreadTornDown)) {
       AllocatorQuarantine.Put(&ThreadQuarantineCache,
                               QuarantineCallback(&Cache), Chunk, OldSize);
     } else {
       SpinMutexLock l(&FallbackMutex);
       AllocatorQuarantine.Put(&FallbackQuarantineCache,
                               QuarantineCallback(&FallbackAllocatorCache),
                               Chunk, OldSize);
     }
   }
   return NewPtr;
 }
开发者ID:CSI-LLVM,项目名称:compiler-rt,代码行数:41,代码来源:scudo_allocator.cpp

示例2: m_file

File::File(const char *fileName, Mode mode) :
    m_file(::open(fileName, 0)),
    m_size(0),
    m_cTime(0),
    m_mTime(0),
    m_aTime(0),
    m_permissions(0)
{
    if (isValid())
    {
        struct stat st;

        if (LIKELY(::fstat(m_file, &st) != -1))
        {
            m_size = st.st_size;
            m_cTime = st.st_ctime;
            m_mTime = st.st_mtime;
            m_aTime = st.st_atime;
            m_permissions = translatePermissions(st);
        }
    }
}
开发者ID:vilkov,项目名称:lvfs-core,代码行数:22,代码来源:lvfs_core_File.cpp

示例3: filterRootById

static ContainerNode& filterRootById(ContainerNode& rootNode, const CSSSelector& firstSelector)
{
    if (!rootNode.inDocument())
        return rootNode;
    if (rootNode.document().inQuirksMode())
        return rootNode;

    // If there was an Id match in the rightmost Simple Selector, we should be in a RightMostWithIdMatch, not in filter.
    // Thus we can skip the rightmost match.
    const CSSSelector* selector = &firstSelector;
    do {
        ASSERT(selector->match() != CSSSelector::Id);
        if (selector->relation() != CSSSelector::SubSelector)
            break;
        selector = selector->tagHistory();
    } while (selector);

    bool inAdjacentChain = false;
    for (; selector; selector = selector->tagHistory()) {
        if (selector->match() == CSSSelector::Id) {
            const AtomicString& idToMatch = selector->value();
            if (ContainerNode* searchRoot = rootNode.treeScope().getElementById(idToMatch)) {
                if (LIKELY(!rootNode.treeScope().containsMultipleElementsWithId(idToMatch))) {
                    if (inAdjacentChain)
                        searchRoot = searchRoot->parentNode();
                    if (searchRoot && (isTreeScopeRoot(rootNode) || searchRoot == &rootNode || searchRoot->isDescendantOf(&rootNode)))
                        return *searchRoot;
                }
            }
        }
        if (selector->relation() == CSSSelector::SubSelector)
            continue;
        if (selector->relation() == CSSSelector::DirectAdjacent || selector->relation() == CSSSelector::IndirectAdjacent)
            inAdjacentChain = true;
        else
            inAdjacentChain = false;
    }
    return rootNode;
}
开发者ID:ikiw,项目名称:webkit,代码行数:39,代码来源:SelectorQuery.cpp

示例4: supportsToArray

bool supportsToArray(ObjectData* obj) {
  if (obj->isCollection()) {
    assertx(isValidCollection(obj->collectionType()));
    return true;
  } else if (UNLIKELY(obj->getAttribute(ObjectData::CallToImpl))) {
    return obj->instanceof(SimpleXMLElement_classof());
  } else if (UNLIKELY(obj->instanceof(SystemLib::s_ArrayObjectClass))) {
    return true;
  } else if (UNLIKELY(obj->instanceof(SystemLib::s_ArrayIteratorClass))) {
    return true;
  } else if (UNLIKELY(obj->instanceof(c_Closure::classof()))) {
    return true;
  } else if (UNLIKELY(obj->instanceof(DateTimeData::getClass()))) {
    return true;
  } else {
    if (LIKELY(!obj->hasInstanceDtor())) {
      return true;
    }

    return false;
  }
}
开发者ID:GokuMizuno,项目名称:hhvm,代码行数:22,代码来源:ext_heapgraph.cpp

示例5: GetOut

void flext_base::ToSysAtom(int n,const t_atom &at) const 
{ 
    outlet *o = GetOut(n); 
    if(LIKELY(o)) { 
        CRITON(); 
        if(IsSymbol(at))
            outlet_symbol((t_outlet *)o,const_cast<t_symbol *>(GetSymbol(at))); 
        else if(IsFloat(at))
            outlet_float((t_outlet *)o,GetFloat(at)); 
#if FLEXT_SYS == FLEXT_SYS_MAX
        else if(IsInt(at))
            outlet_flint((t_outlet *)o,GetInt(at));
#endif
#if FLEXT_SYS == FLEXT_SYS_PD
        else if(IsPointer(at))
            outlet_pointer((t_outlet *)o,GetPointer(at)); 
#endif
        else
            error("Atom type not supported");
        CRITOFF(); 
    } 
}
开发者ID:IcaroL2ORK,项目名称:pd,代码行数:22,代码来源:flout.cpp

示例6: getValueRef

CVarRef APCLocalArray::getValueRef(ssize_t pos) const {
    APCHandle *sv = m_arr->getValue(pos);
    DataType t = sv->getType();
    if (!IS_REFCOUNTED_TYPE(t)) {
        return APCTypedValue::fromHandle(sv)->asCVarRef();
    }
    if (LIKELY(m_localCache != nullptr)) {
        assert(unsigned(pos) < m_arr->capacity());
        TypedValue* tv = &m_localCache[pos];
        if (tv->m_type != KindOfUninit) {
            return tvAsCVarRef(tv);
        }
    } else {
        static_assert(KindOfUninit == 0, "must be 0 since we use smart_calloc");
        unsigned cap = m_arr->capacity();
        m_localCache = (TypedValue*) smart_calloc(cap, sizeof(TypedValue));
    }
    TypedValue* tv = &m_localCache[pos];
    tvAsVariant(tv) = sv->toLocal();
    assert(tv->m_type != KindOfUninit);
    return tvAsCVarRef(tv);
}
开发者ID:Hillgod,项目名称:hiphop-php,代码行数:22,代码来源:apc-local-array.cpp

示例7: unlink_material_cb

static void unlink_material_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *te,
                               TreeStoreElem *tsep, TreeStoreElem *UNUSED(tselem))
{
	Material **matar = NULL;
	int a, totcol = 0;
	
	if (GS(tsep->id->name) == ID_OB) {
		Object *ob = (Object *)tsep->id;
		totcol = ob->totcol;
		matar = ob->mat;
	}
	else if (GS(tsep->id->name) == ID_ME) {
		Mesh *me = (Mesh *)tsep->id;
		totcol = me->totcol;
		matar = me->mat;
	}
	else if (GS(tsep->id->name) == ID_CU) {
		Curve *cu = (Curve *)tsep->id;
		totcol = cu->totcol;
		matar = cu->mat;
	}
	else if (GS(tsep->id->name) == ID_MB) {
		MetaBall *mb = (MetaBall *)tsep->id;
		totcol = mb->totcol;
		matar = mb->mat;
	}
	else {
		BLI_assert(0);
	}

	if (LIKELY(matar != NULL)) {
		for (a = 0; a < totcol; a++) {
			if (a == te->index && matar[a]) {
				matar[a]->id.us--;
				matar[a] = NULL;
			}
		}
	}
}
开发者ID:YasirArafath,项目名称:blender-git,代码行数:39,代码来源:outliner_tools.c

示例8: DLinkList_append

void DLinkList_append(DLinkList dest, DLinkList src) {
	if(UNLIKELY(src->len == 0)) {
		return;
	}
	if(LIKELY(dest->list != NULL)) {
		DLink dhead = dest->list;
		DLink dtail = dhead->prev;
		DLink shead = src->list;
		DLink stail = shead->prev;

		dtail->next = shead;
		shead->prev = dtail;
		stail->next = dhead;
		dhead->prev = stail;
	} else {
		dest->list = src->list;
	}
	dest->len += src->len;
	/* reset src list*/
	src->list = NULL;
	src->len = 0;
}
开发者ID:codesun,项目名称:xetn,代码行数:22,代码来源:dlinklist.c

示例9: reverse_comple

static void reverse_comple(const char* seq, char* rc) {
	int32_t end = strlen(seq), start = 0;
	static const int8_t rc_table[128] = {
		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
		4, 84, 4, 71, 4,  4,  4, 67, 4, 4, 4, 4,  4, 4, 4, 4,
		4, 4,  4, 4,  65, 65, 4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
		4, 84, 4, 71, 4,  4,  4, 67, 4, 4, 4, 4,  4, 4, 4, 4,
		4, 4,  4, 4,  65, 65, 4, 4,  4, 4, 4, 4,  4, 4, 4, 4
	};
	rc[end] = '\0';
	-- end;
	while (LIKELY(start < end)) {
		rc[start] = (char)rc_table[(int8_t)seq[end]];
		rc[end] = (char)rc_table[(int8_t)seq[start]];
		++ start;
		-- end;
	}
	if (start == end) rc[start] = (char)rc_table[(int8_t)seq[start]];
}
开发者ID:jeffdaily,项目名称:Complete-Striped-Smith-Waterman-Library,代码行数:22,代码来源:main.c

示例10: BKE_mesh_cd_validate

/**
 * Duplicate of BM_mesh_cd_validate() for Mesh data.
 */
void BKE_mesh_cd_validate(Mesh *me)
{
	int totlayer_mtex = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
	int totlayer_uv = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
	int mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY);
	int uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV);
	int i;

	if (LIKELY(totlayer_mtex == totlayer_uv)) {
		/* pass */
	}
	else if (totlayer_mtex < totlayer_uv) {
		do {
			const char *from_name =  me->ldata.layers[uv_index + totlayer_mtex].name;
			CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, from_name);
			CustomData_set_layer_unique_name(&me->pdata, totlayer_mtex);
		} while (totlayer_uv != ++totlayer_mtex);
		mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY);
	}
	else if (totlayer_uv < totlayer_mtex) {
		do {
			const char *from_name = me->pdata.layers[mtex_index + totlayer_uv].name;
			CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, from_name);
			CustomData_set_layer_unique_name(&me->ldata, totlayer_uv);
		} while (totlayer_mtex != ++totlayer_uv);
		uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV);
	}

	BLI_assert(totlayer_mtex == totlayer_uv);

	/* Check uv/tex names match as well!!! */
	for (i = 0; i < totlayer_mtex; i++, mtex_index++, uv_index++) {
		const char *name_src = me->pdata.layers[mtex_index].name;
		const char *name_dst = me->ldata.layers[uv_index].name;
		if (!STREQ(name_src, name_dst)) {
			BKE_mesh_uv_cdlayer_rename_index(me, mtex_index, uv_index, -1, name_src, false);
		}
	}
}
开发者ID:Eibriel,项目名称:kiriblender,代码行数:42,代码来源:mesh_validate.c

示例11: assert

void c_ExternalThreadEventWaitHandle::enterContext(context_idx_t ctx_idx) {
  assert(AsioSession::Get()->getContext(ctx_idx));

  // stop before corrupting unioned data
  if (isFinished()) {
    return;
  }

  // already in the more specific context?
  if (LIKELY(getContextIdx() >= ctx_idx)) {
    return;
  }

  assert(getState() == STATE_WAITING);

  if (isInContext()) {
    getContext()->unregisterExternalThreadEvent(m_index);
  }

  setContextIdx(ctx_idx);
  m_index = getContext()->registerExternalThreadEvent(this);
}
开发者ID:Parent5446,项目名称:hiphop-php,代码行数:22,代码来源:external_thread_event_wait_handle.cpp

示例12: f_array_keys

Variant f_array_keys(CVarRef input, CVarRef search_value /* = null_variant */,
                     bool strict /* = false */) {
  const auto& cell_input = *input.asCell();
  if (UNLIKELY(!isContainer(cell_input))) {
    goto warn;
  }
  {
    // We treat Sets differently. For Sets, we pretend the values are
    // also the keys (similar to how Set::toArray() behaves).
    bool isSetType =
      cell_input.m_type == KindOfObject &&
      cell_input.m_data.pobj->getCollectionType() == Collection::SetType;
    if (UNLIKELY(isSetType)) {
      return arrayKeysSetHelper(cell_input, search_value, strict);
    }
    ArrayIter iter(cell_input);
    if (LIKELY(!search_value.isInitialized())) {
      PackedArrayInit ai(getContainerSize(cell_input));
      for (; iter; ++iter) {
        ai.append(iter.first());
      }
      return ai.toArray();
    }

    Array ai = Array::attach(HphpArray::MakeReserve(0));
    for (; iter; ++iter) {
      if ((strict && HPHP::same(iter.secondRefPlus(), search_value)) ||
          (!strict && HPHP::equal(iter.secondRefPlus(), search_value))) {
        ai.append(iter.first());
      }
    }
    return ai;
  }
warn:
  raise_warning("array_keys() expects parameter 1 to be an array "
                "or collection");
  return uninit_null();
}
开发者ID:barkinet,项目名称:hhvm,代码行数:38,代码来源:ext_array.cpp

示例13: assert

void c_ContinuationWaitHandle::enterContext(context_idx_t ctx_idx) {
  assert(AsioSession::Get()->getContext(ctx_idx));

  // stop before corrupting unioned data
  if (isFinished()) {
    return;
  }

  // already in the more specific context?
  if (LIKELY(getContextIdx() >= ctx_idx)) {
    return;
  }

  switch (getState()) {
    case STATE_BLOCKED:
      // enter child into new context recursively
      assert(dynamic_cast<c_WaitableWaitHandle*>(m_child.get()));
      static_cast<c_WaitableWaitHandle*>(m_child.get())->enterContext(ctx_idx);
      setContextIdx(ctx_idx);
      break;

    case STATE_SCHEDULED:
      // reschedule so that we get run
      setContextIdx(ctx_idx);
      getContext()->schedule(this);
      break;

    case STATE_RUNNING: {
      Object e(SystemLib::AllocInvalidOperationExceptionObject(
          "Detected cross-context dependency cycle. You are trying to depend "
          "on something that is running you serially."));
      throw e;
    }

    default:
      assert(false);
  }
}
开发者ID:gilshwartz,项目名称:hiphop-php,代码行数:38,代码来源:continuation_wait_handle.cpp

示例14: dict_sym_iter

/* iterators */
dict_si_t
dict_sym_iter(dict_t d)
{
/* uses static state */
	static BDBCUR *c;
	dict_si_t res;
	const void *vp;
	int z[1U];

	if (UNLIKELY(c == NULL)) {
		c = tcbdbcurnew(d);
		tcbdbcurjump(c, SYM_SPACE, sizeof(SYM_SPACE));
	}

	if (UNLIKELY((vp = tcbdbcurval3(c, z)) == NULL)) {
		goto null;
	} else if (*z != sizeof(int)) {
		goto null;
	}
	/* otherwise fill res */
	res.sid = *(const int*)vp;

	if (UNLIKELY((vp = tcbdbcurkey3(c, z)) == NULL)) {
		goto null;
	}
	/* or fill */
	res.sym = vp;
	/* also iterate to the next thing */
	tcbdbcurnext(c);
	return res;

null:
	if (LIKELY(c != NULL)) {
		tcbdbcurdel(c);
	}
	c = NULL;
	return (dict_si_t){};
}
开发者ID:hroptatyr,项目名称:gandalf,代码行数:39,代码来源:gand-dict-tokyo.c

示例15: MEMHEAD_FROM_PTR

void *MEM_lockfree_reallocN_id(void *vmemh, size_t len, const char *str)
{
	void *newp = NULL;

	if (vmemh) {
		MemHead *memh = MEMHEAD_FROM_PTR(vmemh);
		size_t old_len = MEM_allocN_len(vmemh);

		if (LIKELY(!MEMHEAD_IS_ALIGNED(memh))) {
			newp = MEM_lockfree_mallocN(len, "realloc");
		}
		else {
			MemHeadAligned *memh_aligned = MEMHEAD_ALIGNED_FROM_PTR(vmemh);
			newp = MEM_lockfree_mallocN_aligned(
				old_len,
				(size_t)memh_aligned->alignment,
				"realloc");
		}

		if (newp) {
			if (len < old_len) {
				/* shrink */
				memcpy(newp, vmemh, len);
			}
			else {
				/* grow (or remain same size) */
				memcpy(newp, vmemh, old_len);
			}
		}

		MEM_lockfree_freeN(vmemh);
	}
	else {
		newp = MEM_lockfree_mallocN(len, str);
	}

	return newp;
}
开发者ID:UPBGE,项目名称:blender,代码行数:38,代码来源:mallocn_lockfree_impl.c


注:本文中的LIKELY函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。