Search

2025-02-06

InternalBuffer 개선
가안
1.
기존 이중 버퍼(buf와 row)를 하나의 buf로 제작
2.
row를 이용한 작업을 단일 버퍼로 변경함에 따라 상태를 적용하여 switch-case 구문 활용
3.
System.arraycopy() 작업 (buf → row) 를 줄이고, 단일 버퍼에서 buf의 남은 부분을 재배치 하는 전략 적용
boolean fill(){ int cnt; switch (state){ case INITIAL: limit = read(pos); state = BufferState.PROGRESSING; return true; case PROGRESSING: /** * if begin > limit * cnt = read(begin - pos); * if pos == 0 * extend() 확장 * cnt = read(begin) 확장된 begin 부터 확장된 buf의 끝까지 READ_SIZE 만큼 읽기 * cnt == -1일 경우 limit는 변화없음; state = LAST_LINE * cnt > -1일 경우 limit += cnt; state 변화 없음 * else pos > 0 * relocate() 재배치 begin - pos = 남은 데이터 길이 * 남은 데이터 길이를 buf의 0부터 재배치 * cnt = read(begin - pos); bigin - pos 부터 buf의 끝까지 READ_SIZE 만큼 읽기 * cnt == -1일 경우 limit 변화없음; state = LAST_LINE; * cnt > -1일 경우 limit = begin - pos + cnt; */ return true; case LAST_LINE: /** * if pos == limit State = EOF * 어차피 마지막 라인이기에 읽을 수 있음 * state = EOF로 변환 */ return false; case EOF: return false; } }
Java
복사