- 1
- 2
- 3
- 4
- 5
connector* getConnector( int id )
{
autolock_read<lock_rw_t> alr( _lock );
return _getConnector(id);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
connector* getConnector( int id )
{
autolock_read<lock_rw_t> alr( _lock );
return _getConnector(id);
}
П-потокобезопасность
−2
namespace spine {
static SkeletonBatch* instance = nullptr;
void SkeletonBatch::setBufferSize (int vertexCount) {
if (instance) delete instance;
instance = new SkeletonBatch(vertexCount);
}
SkeletonBatch* SkeletonBatch::getInstance () {
if (!instance) instance = new SkeletonBatch(8192);
return instance;
}
SkeletonBatch::SkeletonBatch (int capacity) :
_capacity(capacity), _position(0)
{
_buffer = new V3F_C4B_T2F[capacity];
_firstCommand = new Command();
_command = _firstCommand;
Director::getInstance()->getScheduler()->scheduleUpdate(this, -1, false);
}
SkeletonBatch::~SkeletonBatch () {
Director::getInstance()->getScheduler()->unscheduleUpdate(this);
Command* command = _firstCommand;
while (command) {
Command* next = command->next;
delete command;
command = next;
}
delete [] _buffer;
}
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-cocos2dx/3/src/spine/SkeletonBatch.cpp
Это просто шедевЕр! Течет как ссаные тряпки...
+4
#define key \
keySequence.keys[i]
#define read_helper(val_) \
file.read( \
reinterpret_cast<char*>(&key.val_), \
sizeof(decltype(key.val_)) \
)
for (DWORD i = 0; i < keyPointer.Count; i++)
read_helper(RotationQuaternion);
for (DWORD i = 0; i < keyPointer.Count; i++)
read_helper(TimeValue);
for (DWORD i = 0; i < keyPointer.Count; i++)
read_helper(PositionValue),
key.SwapBytes();
#undef read_helper
#undef key
+9
#define public public: void operator delete(void *pituh) {}; public
class poteklo
{
public:
poteklo() :
TheAnswer(42)
{
;
}
private:
int TheAnswer;
};
int main(int argc, char *argv[])
{
poteklo *uteklo = new poteklo;
delete uteklo; // Утекло!
return 0;
}
Макро в духе "#define TRUE FALSE", только хардкорнее.
https://ideone.com/ZdGnuL
0
//...
/* See if this is something like X * C - X or vice versa or
if the multiplication is written as a shift. If so, we can
distribute and make a new multiply, shift, or maybe just
have X (if C is 2 in the example above). But don't make
something more expensive than we had before. */
if (SCALAR_INT_MODE_P (mode))
{
rtx lhs = op0, rhs = op1;
wide_int coeff0 = wi::one (GET_MODE_PRECISION (mode));
wide_int coeff1 = wi::one (GET_MODE_PRECISION (mode));
if (GET_CODE (lhs) == NEG)
{
coeff0 = wi::minus_one (GET_MODE_PRECISION (mode));
lhs = XEXP (lhs, 0);
}
else if (GET_CODE (lhs) == MULT
&& CONST_SCALAR_INT_P (XEXP (lhs, 1)))
{
coeff0 = std::make_pair (XEXP (lhs, 1), mode);
lhs = XEXP (lhs, 0);
}
else if (GET_CODE (lhs) == ASHIFT
&& CONST_INT_P (XEXP (lhs, 1))
&& INTVAL (XEXP (lhs, 1)) >= 0
&& INTVAL (XEXP (lhs, 1)) < GET_MODE_PRECISION (mode))
{
coeff0 = wi::set_bit_in_zero (INTVAL (XEXP (lhs, 1)),
GET_MODE_PRECISION (mode));
lhs = XEXP (lhs, 0);
}
if (GET_CODE (rhs) == NEG)
{
coeff1 = wi::minus_one (GET_MODE_PRECISION (mode));
rhs = XEXP (rhs, 0);
}
else if (GET_CODE (rhs) == MULT
&& CONST_INT_P (XEXP (rhs, 1)))
{
coeff1 = std::make_pair (XEXP (rhs, 1), mode);
rhs = XEXP (rhs, 0);
}
else if (GET_CODE (rhs) == ASHIFT
&& CONST_INT_P (XEXP (rhs, 1))
&& INTVAL (XEXP (rhs, 1)) >= 0
&& INTVAL (XEXP (rhs, 1)) < GET_MODE_PRECISION (mode))
{
coeff1 = wi::set_bit_in_zero (INTVAL (XEXP (rhs, 1)),
GET_MODE_PRECISION (mode));
rhs = XEXP (rhs, 0);
}
if (rtx_equal_p (lhs, rhs))
{
rtx orig = gen_rtx_PLUS (mode, op0, op1);
rtx coeff;
bool speed = optimize_function_for_speed_p (cfun);
coeff = immed_wide_int_const (coeff0 + coeff1, mode);
tem = simplify_gen_binary (MULT, mode, lhs, coeff);
return (set_src_cost (tem, mode, speed)
<= set_src_cost (orig, mode, speed) ? tem : 0);
}
}
https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/simplify-rtx.c?view=markup&pathrev=232689#l2062 здоровенная такая функция из недр GCC, в которой делаются оптимизации, это сродни символьным вычислениям вообще говоря
https://godbolt.org/g/vcEqe7 но похоже эта хрень работает плохо, не смогло оно выявить тождественность умножения сдвигами и обычного умножения, сведя операции к return 1 в случае функции test1. Но я естественно находил и примеры кода, которые GCC смог успешно "редуцировать" своим оптимизатором, а clang тупил. Говно тут в том, что вместо того, чтобы впилить нормальную систему символьных вычислений, там нагородили какого-то ебучего говна... Хотя может быть я чего-то не понимаю в компиляторах. Надо будет дракона почитать
+2
CharT getline(std::istream& i, string& s, const CharT* delim) {
...
if (!i.operator void*())
break;
...
}
Библиотека Apache UIMA-CPP.
Что могло заставить написать так, вместо обычного if (i)? Какой-то древний компилятор, который не использует каст к указателю в условии?
Ну и, разумеется, в C++11 ios::operator void*() заменили на explicit ios::operator bool(), так что работать перестало.
+1
void Game::Loadlevel(int which){
stealthloading=0;
if(which==0)Loadlevel((char *)":Data:Maps:map1");
else if(which==1)Loadlevel((char *)":Data:Maps:map2");
else if(which==2)Loadlevel((char *)":Data:Maps:map3");
// [...]
}
// [Почему (char *)? Да вот же!]
void Game::Loadlevel(char *name){
int i,j,k,l,m;
static int oldlevel;
int templength;
float lamefloat;
int lameint;
// [...]
}
Ебём const машиной Тьюринга. Всё тот же https://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp , прямо-таки сокровищница с говном.
+4
if(((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim)||player[i].skeleton.free)&&((player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim)||player[k].skeleton.free))
if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
//If hit by body
if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
static float gLoc[3];
// ...
Не могу не запостить. Кажется, это самый длинный говнокод, что я видел.
По мотиву #20073, из http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp .
PS, на всякий случай поставлю C++ - где-то в недрах второй строчки он наверняка есть.
+6
for(int i = 0; i < codes.size(); ++i) {
switch(i) {
case 0: ret.code0 = codes[i]; break;
case 1: ret.code1 = codes[i]; break;
case 2: ret.code2 = codes[i]; break;
case 3: ret.code3 = codes[i]; break;
case 4: ret.code4 = codes[i]; break;
case 5: ret.code5 = codes[i]; break;
}
}
А всё потому, что ret.code[0-5] - битовые поля. Эх.
+5
//Collisions
static float collisionradius;
if(numplayers>1)
for(k=0;k<numplayers;k++){
for(i=k;i<numplayers;i++){
if(i==k)i++;
if(i<numplayers)
if((animation[player[i].targetanimation].attack!=reversed&&animation[player[i].targetanimation].attack!=reversal&&animation[player[k].targetanimation].attack!=reversed&&animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
if((animation[player[i].currentanimation].attack!=reversed&&animation[player[i].currentanimation].attack!=reversal&&animation[player[k].currentanimation].attack!=reversed&&animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz&&player[k].skeleton.oldfree==player[k].skeleton.free&&player[i].skeleton.oldfree==player[i].skeleton.free&&player[i].targetanimation!=climbanim&&player[i].targetanimation!=hanganim&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim)
if(player[i].coords.y>player[k].coords.y-3)
if(player[i].coords.y<player[k].coords.y+3)
if(player[i].coords.x>player[k].coords.x-3)
if(player[i].coords.x<player[k].coords.x+3)
if(player[i].coords.z>player[k].coords.z-3)
if(player[i].coords.z<player[k].coords.z+3){
if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
if(player[i].onfire||player[k].onfire){
if(!player[i].onfire)player[i].CatchFire();
if(!player[k].onfire)player[k].CatchFire();
}
}
...
http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp#l7276