- 1
final int mazeBlockSize = mazeBlock.getIconWidth(); // it is square, OKAY?!
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+70
final int mazeBlockSize = mazeBlock.getIconWidth(); // it is square, OKAY?!
Как я пакмена писал
+129
#include <stdio.h>
#include <conio.h>
#include <string.h>
void swap (char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(char *a, int i, int n)
{
int j;
if (i == n)
printf("%s\n", a);
else
{
for (j = i; j <= n; j++)
{
swap((a+i), (a+j));
permute(a, i+1, n);
swap((a+i), (a+j));
}
}
}
int main()
{
char str[80] ;
int len=0,i;
puts("Enter a string:\n\n");
gets(str);
for (i=0; str[i] != '\0'; i++)
{
len++;
}
permute(str, 0, len);
getchar();
return 0;
}
Источник:
http://www.c-program-example.com/2012/04/c-program-to-find-all-permutations-of.html
про strlen видимо никто не слышал
+155
getCastIds:
function(checkCast){
var i
, castIds = [this.cancelBlesId]
;
if(checkCast)
{
for(i = 0; i < castIds.length; i++)
{
if(Empire.asset(castIds[i]))
{
castIds.splice(i,1);
i--;
}
}
}
return castIds.length ? castIds : [0];
}
Выстрелим себе в ногу.
+132
У МИНЯ ЕСТЬ АЙФОН 5 И БАЛЬШОЙ ДОМ В МАЙНКРАВТЕ А ЧИВО ДАБИЛСЯ ТЫ?
Я БАГАТ И УСПЕШОН
+86
procedure TForm1.Colorize;
procedure SetStr(var s: string; const Style: TFontStyles; const Color, BackColor: Byte);
var
Format: TCharFormat2;
begin
If s<>'' Then
begin
FillChar(Format, SizeOf(Format), 0);
Format.cbSize := SizeOf(Format);
Format.dwMask:= CFM_BACKCOLOR or CFM_COLOR;
Format.crBackColor:= GetIRCColor(BackColor, True);
Format.crTextColor:= GetIRCColor(Color);
if RichEdit1.HandleAllocated then
SendMessage(RichEdit1.Handle, EM_SETCHARFORMAT, SCF_SELECTION,
LPARAM(@Format));
RichEdit1.SelAttributes.Style:= Style;
RichEdit1.SelText:= s;
RichEdit1.SelAttributes.Assign(RichEdit1.DefAttributes);
s:= ''
end;
end;
var
Color, BackColor: Byte;
Style: TFontStyles;
CurrStr: string;
I: Integer;
begin
Style:= [];
Color:= DefForeColor;
BackColor:= DefBackColor;
CurrStr:= '';
I:= 0;
While (I<Length(Str))do
begin
Inc(I);
case Str[I] of
#31:
begin
SetStr(CurrStr, Style, Color, BackColor);
If fsUnderLine in Style Then
Exclude(Style, fsUnderLine)
else
Include(Style, fsUnderLine);
end;
#2:
begin
SetStr(CurrStr, Style, Color, BackColor);
If fsBold in Style Then
Exclude(Style, fsBold)
else
Include(Style, fsBold);
end;
#15, #13:
begin
SetStr(CurrStr, Style, Color, BackColor);
Color:= DefForeColor;
BackColor:= DefBackColor;
end;
#3:
begin
SetStr(CurrStr, Style, Color, BackColor);
Inc(I);
Color:= DefForeColor;
If (Str[I] in ['0', '1'..'9'])Then
begin
Color:= StrToInt(Str[I]);
Inc(I);
If (Str[I] in ['0', '1'..'9'])Then
begin
Color:= StrToInt(IntToStr(Color)+Str[I]);
Inc(I)
end;
end;
If Str[I] = ',' Then //BackColor
begin
BackColor:= DefBackColor;
Inc(I);
If (Str[I] in ['0', '1'..'9'])Then
begin
BackColor:= StrToInt(Str[I]);
Inc(I);
If (Str[I] in ['0', '1'..'9'])Then
begin
BackColor:= StrToInt(IntToStr(BackColor)+Str[I]);
Inc(I)
end;
end;
end;
Dec(I)
end;
else
CurrStr:= CurrStr+Str[I]
end;
end;
SetStr(CurrStr, Style, Color, BackColor);
end;
Процедура раскрашивающая текст из Log-файла mIRC загруженого в TRichEdit на форме.
function GetIRCColor(const Color: Byte; const Back: Boolean=False): TColor;
begin
case Color of
0: Result:= clWhite;
1: Result:= clBlack;
2: Result:= clNavy;
3: Result:= clGreen;
4: Result:= clRed;
5: Result:= clMaroon;
6: Result:= clPurple;
7: Result:= $000080FF;
8: Result:= clYellow;
9: Result:= clLime;
10: Result:= clTeal;
11: Result:= clAqua;
12: Result:= clBlue;
13: Result:= clFuchsia;
14: Result:= clGray;
15: Result:= clSilver;
else
begin
If Back Then
Result:= clWhite
else
Result:= clBlack
end;
end;
end;
+11
const listee* const nullablya = static_cast<listee*>(lst1);
if(nullablya == NULL)
+6
list* down_if_valid_me(void)
{
return this ? this->down() : NULL;
}
+157
if (is_array(reset((array)$patentInfo))) {
// ...
}
+123
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef struct {
char * begin;
uint64_t size, data_size;
} str_t;
inline uint64_t max(uint64_t a, uint64_t b) {
return (a > b) ? a : b;
}
inline str_t correct_data_size(str_t str, uint64_t new_size) {
if(str.data_size < new_size) {
str.data_size = (max(str.data_size, new_size) << 1);
str.begin = realloc(str.begin, str.data_size);
}
return str;
}
inline str_t concat(str_t dest, str_t src) {
uint64_t new_size = (dest.size + src.size - 1);
dest = correct_data_size(dest, new_size);
memcpy((dest.begin + dest.size - 1), src.begin, src.size);
dest.size = new_size;
return dest;
}
inline str_t create_str(char * str, uint64_t size) {
return (str_t){.begin = strcat(malloc(size), str), .size = size, .data_size = size};
}
inline void print_str_t(str_t str) {
fprintf(stderr, "str = %ssize = %lu, data_size = %lu\n", str.begin, str.size, str.data_size);
}
uint64_t test(uint64_t star_n, uint64_t n, str_t str, str_t * gstr) {
uint64_t end = (star_n + n);
do {
*gstr = concat(*gstr, str);
char * pos = gstr->begin;
while((pos = strstr(pos, "efgh")))
memcpy(pos,"____",4);
} while((++star_n) != end);
return star_n;
}
int main(void) {
char data[] = "abcdefghefghefgh";
str_t str = create_str(data, sizeof(data));
str_t gstr = create_str("", 1);
time_t starttime = time(NULL);
uint64_t block_c = 0;
while((block_c = test(block_c, ((256/16) * 1024), str, &gstr)) != (((256/16) * 1024) * 20))
printf("%ldsec\t\t%lukb\n",time(NULL)-starttime,gstr.size/1024);
}
Минимально оптимизированный вариант в царь-стиле теста из предыдущего ГК. Никто не увидел и начали на меня кукарекать. То ещё ГК, давайте объясняйте что здесь говно.
+126
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(){
setbuf(stdout,NULL); //disable output buffering
char *str=malloc(8);
strcpy(str,"abcdefgh");
str=realloc(str,strlen(str)+8);
strcat(str,"efghefgh"); //sprintf(str,"%s%s",str,"efghefgh");
int imax=1024/strlen(str)*1024*4;
printf("%s","exec.tm.sec\tstr.length\n"); //fflush(stdout);
time_t starttime=time(NULL);
char *gstr=malloc(0);
int i=0;
char *pos;
int lngth;
char *pos_c=gstr;
int str_len=strlen(str);
while(i++ < imax+1000){
lngth=strlen(str)*i;
gstr=realloc(gstr,lngth+str_len);
strcat(gstr,str); //sprintf(gstr,"%s%s",gstr,str);
pos_c+=str_len;
pos=gstr;
while(pos=strstr(pos,"efgh")){
memcpy(pos,"____",4);
}
if(lngth % (1024*256)==0){
printf("%dsec\t\t%dkb\n",time(NULL)-starttime,lngth/1024); //fflush(stdout);
}
}
//printf("%s\n",gstr);
}
http://raid6.com.au/~onlyjob/posts/arena/ - банальый пример бенчмарков всяких недоЯП. Это новый топ10 шедевр на этот месяц.
Именно про такие бенчи кукарекают питушки, когда ссылаются на какие-то бенчи - самое смешно в этом то, что %подставить имя ЯП% сравнивать с сишкой бесполезно, ибо их стдлиб написана на Си и дрёглает либц. Т.е. сравнивая стдлиб разных ЯП - вы сравниваете сишные реализации и оверхеды самих ЯП.